1
0
Fork 0

Handle better nullable file parameter (#11486)

* Handle better nullable file parameter

Closes #11483

* CS fix
pull/11497/head
Dezső BICZÓ 2023-06-06 21:27:55 +00:00 committed by GitHub
parent 45977c7cb1
commit 8c18de5a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -338,12 +338,22 @@ class JsonFile
$result = $parser->lint($json);
if (null === $result) {
if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) {
if ($file === null) {
throw new \UnexpectedValueException('The input is not UTF-8, could not parse as JSON');
} else {
throw new \UnexpectedValueException('"' . $file . '" is not UTF-8, could not parse as JSON');
}
}
return true;
}
throw new ParsingException('"'.$file.'" does not contain valid JSON'."\n".$result->getMessage(), $result->getDetails());
if ($file === null) {
throw new ParsingException('The input does not contain valid JSON' . "\n" . $result->getMessage(),
$result->getDetails());
} else {
throw new ParsingException('"' . $file . '" does not contain valid JSON' . "\n" . $result->getMessage(),
$result->getDetails());
}
}
}