Browse Source

Tweak exception messages

Jordi Boggiano 13 years ago
parent
commit
db16f68fbf

+ 0 - 1
src/Composer/Command/ValidateCommand.php

@@ -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;

+ 4 - 3
src/Composer/Json/JsonFile.php

@@ -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());
     }
 }

+ 1 - 2
tests/Composer/Test/Json/JsonFileTest.php

@@ -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());
         }
     }