Skip to content

Don't report errors errors as unhandled if there is an existing "error" event handler#4767

Merged
gaearon merged 8 commits intojestjs:masterfrom
gaearon:int-test
Oct 26, 2017
Merged

Don't report errors errors as unhandled if there is an existing "error" event handler#4767
gaearon merged 8 commits intojestjs:masterfrom
gaearon:int-test

Conversation

@gaearon
Copy link
Copy Markdown
Contributor

@gaearon gaearon commented Oct 26, 2017

This add a failing integration test for behavior React relies on.
It passes before #4669, but now fails.

Demonstrates Fixes #4764.

@SimenB
Copy link
Copy Markdown
Member

SimenB commented Oct 26, 2017

Heh, we fixed lint at the same time

@SimenB
Copy link
Copy Markdown
Member

SimenB commented Oct 26, 2017

Bah, rest args is not available on node 4. Needs arguments. I'll take a step back so we don't try to double fix stuff

@gaearon
Copy link
Copy Markdown
Contributor Author

gaearon commented Oct 26, 2017

Lol. I pushed a commit that tracks the number of user handlers. I think it's more correct because if the user removes the listener, we should restore the original behavior.

@gaearon gaearon changed the title Add failing integration test for rethrowing after nested event loop Don't report errors errors as unhandled if there is an existing "error" event handler Oct 26, 2017
if (name === 'error') {
userErrorListenerCount--;
}
return originalRemoveListener.apply(this, arguments);
Copy link
Copy Markdown
Member

@SimenB SimenB Oct 26, 2017

Choose a reason for hiding this comment

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

should be .apply(global, arguments) as this is wrong in the arrow function, right?

arguments is also wrong within the arrow

// Report uncaught errors.
this.errorEventListener = event => {
if (event.error) {
if (userErrorListenerCount === 0 && event.error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of manual bookkeeping, can we just check the total number of listeners here?

e.g. this works in chrome:

window.getEventListeners(window).error.length // 1 on github.com

Copy link
Copy Markdown
Member

@SimenB SimenB Oct 26, 2017

Choose a reason for hiding this comment

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

Looks like getEventListeners is not available for jsdom@9 at least

EDIT: Or in 11

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm fine with upgrading to 11 and dropping node 4 now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jest master doesn't seem to catch errors originating from React

4 participants