Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JsonFile.php

function JsonFile::throwEncodeError

Throws an exception according to a given code with a customized message

Parameters

int $code return code of json_last_error function:

Return value

never

Throws

\RuntimeException

1 call to JsonFile::throwEncodeError()
JsonFile::encode in vendor/composer/composer/src/Composer/Json/JsonFile.php
Encodes an array into (optionally pretty-printed) JSON

File

vendor/composer/composer/src/Composer/Json/JsonFile.php, line 309

Class

JsonFile
Reads/writes json files.

Namespace

Composer\Json

Code

private static function throwEncodeError(int $code) : void {
    switch ($code) {
        case JSON_ERROR_DEPTH:
            $msg = 'Maximum stack depth exceeded';
            break;
        case JSON_ERROR_STATE_MISMATCH:
            $msg = 'Underflow or the modes mismatch';
            break;
        case JSON_ERROR_CTRL_CHAR:
            $msg = 'Unexpected control character found';
            break;
        case JSON_ERROR_UTF8:
            $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
            break;
        default:
            $msg = 'Unknown error';
    }
    throw new \RuntimeException('JSON encoding failed: ' . $msg);
}
RSS feed
Powered by Drupal