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

[9.x] Makes ExceptionHandler::renderForConsole internal #40936

Merged
merged 2 commits into from
Feb 10, 2022

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Feb 10, 2022

This pull request makes the ExceptionHandler::renderForConsole internal. For years, Collision overrides the method with its own logic, and as consequence, App\Exceptions\ExceptionHandler::renderForConsole never gets called.

Adding the flag @internal will instruct people that this method is not meant to be overwritten.

Closes #40935.

@taylorotwell taylorotwell merged commit 125850e into 9.x Feb 10, 2022
@taylorotwell taylorotwell deleted the fix/render-for-console branch February 10, 2022 14:38
@kieransimkin
Copy link

okay, so how do you do it then?! How do you catch exceptions thrown within commands, there must be a way, other than wrapping every command runner in a try..catch?!

Why isn't this in the error reporting documentation? when you search for anything relating to "catch errors in commands in laravel", you get old articles telling you to overwrite the renderForConsole, and no official documentation from Laravel on how to achieve the same thing. This isn't good, if there is a solution perhaps you would point me to it, so that I can update the forum posts that are giving out of date information?

@nunomaduro
Copy link
Member Author

@kieransimkin Because we use GitHub hooks, issues get automatically closed once we merged the pull request that solves a particular issue. To catch exceptions from the console, you may use the report method of your application's exception handler.

Of course, you may use app()->runningInConsole() to see if the error is coming from the console.

@kieransimkin
Copy link

My App's report function doesn't get called when an exception happens in console.

@nunomaduro
Copy link
Member Author

Please double check that. I was able to catch exceptions in this example:

Screenshot 2022-02-10 at 15 27 52

Comment on lines +695 to +696
*
* @internal This method is not meant to be used or overwritten outside the framework.
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR marks a method internal which is part of an interface?

class Handler implements ExceptionHandlerContract ->

/**
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Throwable $e
* @return void
*/
public function renderForConsole($output, Throwable $e);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App\Exceptions\Handler::renderForConsole() is ignored
4 participants