Skip to content

Commit

Permalink
Make sure schema issues are always reported correctly, but not in ini…
Browse files Browse the repository at this point in the history
…t when Composer is not required, fixes #9986
  • Loading branch information
Seldaek committed Jun 27, 2021
1 parent 6f992a6 commit e87a150
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Composer/Console/Application.php
Expand Up @@ -420,9 +420,9 @@ public function getComposer($required = true, $disablePlugins = null)
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;
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/Composer/Factory.php
Expand Up @@ -37,6 +37,7 @@
use Composer\Autoload\AutoloadGenerator;
use Composer\Package\Version\VersionParser;
use Composer\Downloader\TransportException;
use Composer\Json\JsonValidationException;
use Seld\JsonLint\JsonParser;

/**
Expand Down Expand Up @@ -308,7 +309,13 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
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);
Expand Down

0 comments on commit e87a150

Please sign in to comment.