1
0
Fork 0

Tweak exception messages

pull/868/merge
Jordi Boggiano 2012-07-03 14:19:19 +02:00
parent ae2fb6be89
commit db16f68fbf
3 changed files with 5 additions and 6 deletions

View File

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

View File

@ -15,6 +15,7 @@ namespace Composer\Json;
use Composer\Composer;
use JsonSchema\Validator;
use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;
use Composer\Util\RemoteFilesystem;
use Composer\Downloader\TransportException;
@ -148,7 +149,7 @@ class JsonFile
foreach ((array) $validator->getErrors() as $error) {
$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;
@ -294,12 +295,12 @@ class JsonFile
$result = $parser->lint($json);
if (null === $result) {
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;
}
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());
}
}

View File

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