Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Command/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$autoloadFile,
$configuration,
$level,
$allowXdebug
$allowXdebug,
$this->getApplication()
);
} catch (\PHPStan\Command\InceptionNotSuccessfulException $e) {
Copy link
Contributor Author

@clxmstaab clxmstaab Nov 6, 2019

Choose a reason for hiding this comment

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

a Exception thrown within a command will automatically lead to a exit-code of 1 by symfony-console

Copy link
Member

Choose a reason for hiding this comment

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

Hi, I disagree with this change. CommandHelper outputs the error message, InceptionNotSuccessfulException signals the AnalyseCommand to return the exit code 1.

Copy link
Member

Choose a reason for hiding this comment

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

This change would lead to a really chaotic output in most cases which isn't needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

InceptionNotSuccessfulException signals the AnalyseCommand to return the exit code 1.

symfony will automatically use a exit-code of 1 when a un-handled exception occurs.
no need to do this here and interrupt the exception handling

Copy link
Contributor

@staabm staabm Nov 6, 2019

Choose a reason for hiding this comment

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

This change would lead to a really chaotic output in most cases which isn't needed.

IMO the cause of chaotic output is that the output is scattered accross CommandHelper and the actual commands. output should be written only in a few places in the upper stack

Copy link
Member

Choose a reason for hiding this comment

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

But the problem is that I don't always want to output the thrown exception with stack trace. I want to present something more friendly to the user.

Copy link
Contributor Author

@clxmstaab clxmstaab Nov 6, 2019

Choose a reason for hiding this comment

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

when letting the exception fly through we would get a error like (no stacktrace)

image

no stacktrace or similar involved.

you get the stacktrace etc. only when adding -v to the command:

image

return 1;
Expand Down
9 changes: 6 additions & 3 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\DependencyInjection\NeonAdapter;
use PHPStan\File\FileFinder;
use PHPStan\File\FileHelper;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -36,7 +37,8 @@ public static function begin(
?string $autoloadFile,
?string $projectConfigFile,
?string $level,
bool $allowXdebug
bool $allowXdebug,
Application $application
): InceptionResult
{
if (!$allowXdebug) {
Expand Down Expand Up @@ -129,7 +131,7 @@ public static function begin(
try {
$projectConfig = $loader->load($projectConfigFile, null);
} catch (\Nette\InvalidStateException | \Nette\FileNotFoundException $e) {
$errorOutput->writeln($e->getMessage());
$application->renderException($e);
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? The message is usually about which file wasn't found which is sufficient.

throw new \PHPStan\Command\InceptionNotSuccessfulException();
}
$defaultParameters = [
Expand Down Expand Up @@ -302,7 +304,8 @@ public static function begin(
require_once $file;
})($bootstrapFile);
} catch (\Throwable $e) {
$errorOutput->writeln($e->getMessage());
$application->renderException($e);

throw new \PHPStan\Command\InceptionNotSuccessfulException();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/DumpDependenciesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$autoloadFile,
$configurationFile,
'0', // irrelevant but prevents an error when a config file is passed
$allowXdebug
$allowXdebug,
$this->getApplication()
);
} catch (\PHPStan\Command\InceptionNotSuccessfulException $e) {
return 1;
Expand Down