diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 177f7220a..77f1ba85c 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -420,9 +420,9 @@ class Application extends BaseApplication exit(1); } } catch (JsonValidationException $e) { - $errors = ' - ' . implode(PHP_EOL . ' - ', $e->getErrors()); - $message = $e->getMessage() . ':' . PHP_EOL . $errors; - throw new JsonValidationException($message); + if ($required) { + throw $e; + } } } diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 6c9891d34..f4fe06274 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -37,6 +37,7 @@ use Composer\EventDispatcher\EventDispatcher; use Composer\Autoload\AutoloadGenerator; use Composer\Package\Version\VersionParser; use Composer\Downloader\TransportException; +use Composer\Json\JsonValidationException; use Seld\JsonLint\JsonParser; /** @@ -308,7 +309,13 @@ class Factory throw new \InvalidArgumentException($message.PHP_EOL.$instructions); } - $file->validateSchema(JsonFile::LAX_SCHEMA); + try { + $file->validateSchema(JsonFile::LAX_SCHEMA); + } catch (JsonValidationException $e) { + $errors = ' - ' . implode(PHP_EOL . ' - ', $e->getErrors()); + $message = $e->getMessage() . ':' . PHP_EOL . $errors; + throw new JsonValidationException($message); + } $jsonParser = new JsonParser; try { $jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS);