Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infection must return appropriate exit status when failing #1299

Merged
merged 2 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->executeCommand($this->getIO());

return 0;
return $this->executeCommand($this->getIO()) ? 0 : 1;
}

abstract protected function executeCommand(IO $io): void;
abstract protected function executeCommand(IO $io): bool;

final protected function getIO(): IO
{
Expand Down
4 changes: 3 additions & 1 deletion src/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function configure(): void
);
}

protected function executeCommand(IO $io): void
protected function executeCommand(IO $io): bool
{
if (!$io->isInteractive()) {
$io->writeln(self::NONINTERACTIVE_MODE_ERROR);
Expand Down Expand Up @@ -156,6 +156,8 @@ protected function executeCommand(IO $io): void
SchemaConfigurationLoader::DEFAULT_DIST_CONFIG_FILE
));
$io->newLine();

return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function configure(): void
;
}

protected function executeCommand(IO $io): void
protected function executeCommand(IO $io): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about keeping void here? In practice we tend to throw an exception in case of an error instead of a boolean value

Copy link
Member Author

@sanmai sanmai Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you propose that we re-throw the exceptions instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually already do since we don't wrap the whole call in with a catch (Throwable $t) (and Symfony already does it). So I don't think forcing this return code is providing anything tbh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we do wrap the other call for two very important exceptions.

{
$logger = new ConsoleLogger($io);
$container = $this->createContainer($io, $logger);
Expand All @@ -238,10 +238,14 @@ protected function executeCommand(IO $io): void

try {
$engine->execute();

return true;
} catch (InitialTestsFailed | MinMsiCheckFailed $exception) {
// TODO: we can move that in a dedicated logger later and handle those cases in the
// Engine instead
$io->error($exception->getMessage());

return false;
}
}

Expand Down