Skip to content

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

Merged
taylorotwell merged 2 commits into
9.xfrom
fix/render-for-console
Feb 10, 2022
Merged

taylorotwell merged 2 commits into
9.xfrom
fix/render-for-console

Conversation

@nunomaduro

@nunomaduro nunomaduro commented Feb 10, 2022 •

Copy link
Copy Markdown
Member

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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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

@nunomaduro

Copy link
Copy Markdown
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
Copy Markdown
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);

salmanarshad321 pushed a commit to salmanarshad321/framework that referenced this pull request Sep 23, 2026
)

* Makes `ExceptionHandler::renderForConsole` internal

* Update Handler.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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