Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Give errors back to error handler if not handled by console.error listeners #22261

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

Merged
merged 1 commit into from
Apr 4, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Apr 3, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22259
License MIT
Doc PR n/a

Re-throws errors if ConsoleErrorEvent::markErrorAsHandled() hasn't been called so that they can reach the global error handler, fixing the BC break.

@curry684
Copy link
Contributor

curry684 commented Apr 3, 2017

BC bug fixes should have a unit test to ensure the issue will not surface again.

@chalasr
Copy link
Member Author

chalasr commented Apr 3, 2017

Yeah, I didn't find a relevant way to test this yet.

@ogizanagi
Copy link
Contributor

Sure, it'll fix the BC break. Thank you for creating the issue and for this PR. 😃

In #20808 however, I also wanted to add support for handling errors natively & easily with the standalone component, when you don't use an error handler like the one in the Debug component.
It may not challenge this PR as is, but it depends how we'd like to proceed. With your solution, we could for instance provide a default error listener in the component, marking errors as handled by the Application and running Application::renderException() (as the DebugHandlersListener does). Problem: the exit code is set to 0 as soon as the event declares the exception is handled.

Regarding the test, why not just testing the error is properly re-thrown by Application? You don't need to test an error handler is called.

@chalasr chalasr force-pushed the console-error-handler branch from 20c4419 to 903ea95 Compare April 4, 2017 08:50
@chalasr chalasr force-pushed the console-error-handler branch from 903ea95 to 5a5bf54 Compare April 4, 2017 08:56
@chalasr
Copy link
Member Author

chalasr commented Apr 4, 2017

Test added, I was missing something.

we could for instance provide a default error listener in the component, marking errors as handled by the Application and running Application::renderException() (as the DebugHandlersListener does).

As discussed together, I think we can first merge this as is in order to fix the introduced BC break and improve the situation in a next time but indeed, having a default error handler in the console seems like a good compromise to me.

PR ready, build failures unrelated.

@chalasr
Copy link
Member Author

chalasr commented Apr 4, 2017

public function execute(InputInterface $input, OutputInterface $output) 
{
    $this->foo();
}

public function fooo() 
{
}

Before:
before

After:
after

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 4, 2017
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍 but please note that I'm going to look at error handling in console a bit more deeply during feat freeze. I may change a few things to what #18140 did.

@fabpot
Copy link
Member

fabpot commented Apr 4, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 5a5bf54 into symfony:master Apr 4, 2017
fabpot added a commit that referenced this pull request Apr 4, 2017
… by console.error listeners (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Console] Give errors back to error handler if not handled by console.error listeners

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22259
| License       | MIT
| Doc PR        | n/a

Re-throws errors if `ConsoleErrorEvent::markErrorAsHandled()` hasn't been called so that they can reach the global error handler, fixing the BC break.

Commits
-------

5a5bf54 [Console] Give errors back to error handlers if not handled by console.error listeners
@chalasr chalasr deleted the console-error-handler branch April 4, 2017 15:09
@chalasr
Copy link
Member Author

chalasr commented Apr 4, 2017

@nicolas-grekas One thing to note is that errors are still not rethrown in case the application has no event dispatcher (occurs only using the component independently), even after this. I just realize it and was going to look into but I'll wait then, don't hesitate to ping me for a hand.

@@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
$e = null;
$exitCode = 0;
Copy link
Member

Choose a reason for hiding this comment

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

technically, the debug handler handles the exception (rendering it in a special way), but could still want to use a failure exit code. We should let the event change the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's the conclusion we came to with @chalasr regarding this part. I guess now it's better to wait for a PR with a bigger vision of the remaining issues with the component, as @nicolas-grekas seems to plan.

fabpot added a commit that referenced this pull request May 11, 2017
…onsole.error listeners (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fix errors not rethrown even if not handled by console.error listeners

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22678
| License       | MIT
| Doc PR        | n/a

#22261 has been squashed while revisiting error handling, this fixes it again while keeping latest changes intact.

__code__
```php
public function execute(InputInterface $input, OutputInterface $output) {
    $this->barr();
}

public function bar() { }
```

__before__
![before](http://image.prntscr.com/image/38aa3b46fed6439ead693908ab104fb3.png)

__after__
![after](http://image.prntscr.com/image/071322bfa52247c6a02eac6ef9d8284a.png)

Commits
-------

75f098f Fix errors not rethrown even if not handled by console.error listeners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.