-
Notifications
You must be signed in to change notification settings - Fork 545
Let exceptions fly while bootstrapping #3
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
Conversation
that way we get a proper exception stacktrace on the CLI
with the 2nd commit we actually give the exception-hanlder the information to tell us about the cause of the exception:
$ php ../phpstan-src/bin/phpstan analyse -c app/partner/phpstan.neon.dist
Required package "complex/rocket" is not installed: cannot detect its version
In CommandHelper.php line 306:
Required package "complex/rocket" is not installed: cannot detect its version
In Versions.php line 103:
Required package "complex/rocket" is not installed: cannot detect its version
analyse [--paths-file PATHS-FILE] [-c|--configuration CONFIGURATION] [-l|--level LEVEL] [--no-progress] [--debug] [-a|--autoload-file AUTOLOAD-FILE] [--error-format ERROR-FORMAT] [--memory-limit MEMORY-LIMIT] [
--xdebug] [--] [<paths>...]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Command/CommandHelper.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, in cases where we throw InceptionNotSuccessfulException with a root-cause exception provided, we should not print our the message manually but let symfony-console do its magic.
(this would apply to a few more places within this file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could print out the stack trace in this place manually. The same way Symfony Console does. Can you investigate what function should we call to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a Symfony\Component\Console\Application::renderException().. I will have a look
IMO having this kind of error handling logik on a command-level is wrong though
There was a problem hiding this comment.
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.
src/Command/CommandHelper.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could print out the stack trace in this place manually. The same way Symfony Console does. Can you investigate what function should we call to do that?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise fine 👍
There was a problem hiding this comment.
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.
There are still many problems with this. Decided not to go with it.
Uh oh!
There was an error while loading. Please reload this page.
with this change we get a proper exception stacktrace on the CLI.
without this change a Exception thrown while bootstrapping will just emit its message, e.g.
$ php ../phpstan-src/bin/phpstan analyse -c app/partner/phpstan.neon.dist Required package "complex/rocket" is not installed: cannot detect its versionafter this changes we get a proper stacktrace, like one would expect who is used to symfony-console applications, which means depending on the use of
-vparameter you get more details about the actual error:adding
-v:DX wise this is a major improvement and saves a lot of time while debugging the cause of a error (without the need to install/activate xdebug)