Skip to content

Commit

Permalink
Merge pull request #406 from ergebnis/feature/errors
Browse files Browse the repository at this point in the history
Enhancement: Show validation error messages
  • Loading branch information
ergebnis-bot authored Apr 19, 2020
2 parents 538357c + 08e4eab commit a53e058
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.3.2...master`][2.3.2...master].

### Changed

* Started showing validation error messages as obtained from validation instead of relying on on executing composer validate ([#406]), by [@localheinz]

## [`2.3.2`][2.3.2]

For a full diff see [`2.3.1...2.3.2`][2.3.1...2.3.2].
Expand Down Expand Up @@ -436,6 +440,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[#374]: https://github.com/ergebnis/composer-normalize/pull/374
[#379]: https://github.com/ergebnis/composer-normalize/pull/379
[#380]: https://github.com/ergebnis/composer-normalize/pull/380
[#406]: https://github.com/ergebnis/composer-normalize/pull/406

[@ergebnis]: https://github.com/ergebnis
[@ergebnis-bot]: https://github.com/ergebnis-bot
Expand Down
8 changes: 3 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.10.1@eeed5ecccc10131397f0eb7ee6da810c0be3a7fc">
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
<file src="src/Application.php">
<PropertyNotSetInConstructor occurrences="1">
<code>Application</code>
Expand All @@ -12,8 +12,7 @@
<code>$formatter</code>
<code>$differ</code>
</MissingPropertyType>
<MixedArgument occurrences="11">
<code>$composerFile</code>
<MixedArgument occurrences="10">
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
Expand Down Expand Up @@ -45,8 +44,7 @@
<code>isLocked</code>
<code>diff</code>
</MixedMethodCall>
<PossiblyInvalidArgument occurrences="9">
<code>$composerFile</code>
<PossiblyInvalidArgument occurrences="8">
<code>$composerFile</code>
<code>$composerFile</code>
<code>$composerFile</code>
Expand Down
43 changes: 10 additions & 33 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,21 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O

try {
$normalized = $this->normalizer->normalize($json);
} catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException $exception) {
} catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException | Normalizer\Exception\NormalizedInvalidAccordingToSchemaException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
$exception->getMessage()
));

return $this->validateComposerFile(
$output,
$composerFile
);
$errors = $exception->errors();

\array_walk($errors, static function (string $error) use ($io): void {
$io->writeError($error);
});

$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');

return 1;
} catch (\RuntimeException $exception) {
$io->writeError(\sprintf(
'<error>%s</error>',
Expand Down Expand Up @@ -348,34 +353,6 @@ private function diff(string $before, string $after): string
);
}

/**
* @see https://getcomposer.org/doc/03-cli.md#validate
*
* @param Console\Output\OutputInterface $output
* @param string $composerFile
*
* @throws \Exception
*
* @return int
*/
private function validateComposerFile(Console\Output\OutputInterface $output, string $composerFile): int
{
/** @var Console\Application $application */
$application = $this->getApplication();

return $application->run(
new Console\Input\ArrayInput([
'command' => 'validate',
'file' => $composerFile,
'--no-check-all' => true,
'--no-check-lock' => true,
'--no-check-publish' => true,
'--strict' => true,
]),
$output
);
}

/**
* @see https://getcomposer.org/doc/03-cli.md#update
*
Expand Down
2 changes: 1 addition & 1 deletion test/Integration/Command/NormalizeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function testFailsWhenComposerJsonIsPresentButNotValid(CommandInvocation
);

self::assertContains($message, $display);
self::assertContains('The property name is required', $display);
self::assertContains('See https://getcomposer.org/doc/04-schema.md for details on the schema', $display);
self::assertContains('No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.', $display);
self::assertEquals($initialState, $scenario->currentState());
}

Expand Down

0 comments on commit a53e058

Please sign in to comment.