Tweak exception messages

main
Jordi Boggiano 12 years ago
parent ae2fb6be89
commit db16f68fbf

@ -91,7 +91,6 @@ EOT
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln('<error>' . $file . ' contains a JSON Syntax Error:</error>');
$output->writeln('<error>' . $e->getMessage() . '</error>'); $output->writeln('<error>' . $e->getMessage() . '</error>');
return 1; return 1;

@ -15,6 +15,7 @@ namespace Composer\Json;
use Composer\Composer; use Composer\Composer;
use JsonSchema\Validator; use JsonSchema\Validator;
use Seld\JsonLint\JsonParser; use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use Composer\Downloader\TransportException; use Composer\Downloader\TransportException;
@ -148,7 +149,7 @@ class JsonFile
foreach ((array) $validator->getErrors() as $error) { foreach ((array) $validator->getErrors() as $error) {
$errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message']; $errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
} }
throw new JsonValidationException('JSON file doesnt match expected schema "'.$this->path.'"', $errors); throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
} }
return true; return true;
@ -294,12 +295,12 @@ class JsonFile
$result = $parser->lint($json); $result = $parser->lint($json);
if (null === $result) { if (null === $result) {
if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) { if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) {
throw new \UnexpectedValueException('JSON file is not UTF-8 encoded "'.$file.'"'); throw new \UnexpectedValueException('"'.$file.'" is not UTF-8, could not parse as JSON');
} }
return true; return true;
} }
throw new JsonValidationException('JSON file is not valid "'.$file.'"'."\n".$result->getMessage(), $result->getDetails()); throw new ParsingException('"'.$file.'" does not contain valid JSON'."\n".$result->getMessage(), $result->getDetails());
} }
} }

@ -198,9 +198,8 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
try { try {
JsonFile::parseJson($json); JsonFile::parseJson($json);
$this->fail(); $this->fail();
} catch (JsonValidationException $e) { } catch (ParsingException $e) {
$this->assertContains($text, $e->getMessage()); $this->assertContains($text, $e->getMessage());
$this->assertNotEmpty($e->getErrors());
} }
} }

Loading…
Cancel
Save