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

Handle ErrorEvents in TraceKit #1162

Closed
wants to merge 5 commits into from
Closed

Handle ErrorEvents in TraceKit #1162

wants to merge 5 commits into from

Conversation

shcallaway
Copy link
Contributor

This PR resolves #1008 . traceKitWindowOnError now handles the case where the ex parameter is an ErrorEvent object.

@shcallaway shcallaway changed the title Bug/error event trace kit Handle ErrorEvents in TraceKit Dec 3, 2017
@michal-rumanek
Copy link

It doesn't cover the case where ErrorEvent is passed as message parameter, so it doesn't resolve #1008.
screen shot 2017-12-04 at 12 47 49

@shcallaway
Copy link
Contributor Author

@michal-rumanek Woops. I misread the original comment. Fixed now.

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

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

Other than this small change, it's ready to be shipped

@@ -89,6 +89,7 @@ describe('utils', function() {
describe('isErrorEvent', function() {
it('should work as advertised', function() {
assert.isFalse(isErrorEvent(new Error()));
assert.isFalse(isError(new ErrorEvent('')));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is isError test, not isErrorEvent and should be moved to line ~122 w. additional supportsErrorEvent() clause, eg. if (supportsErrorEvent()) assert.isFalse(isError(new ErrorEvent('')));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@michal-rumanek
Copy link

@shcallaway Now the error is logged correctly in Sentry panel. Thank you :-)
But, not sure if _oldOnerrorHandler shouldn't be invoked with original message parameter (original ErrorEvent object, not string created by message = message.message).

@shcallaway
Copy link
Contributor Author

@michal-rumanek The core developers would know best, probably. But I can see multiple ways of handling to the case where message is an ErrorEvent. For example, we could route it to the middle else if block by pulling the Error object out, like this:

if (ex && utils.isErrorEvent(ex)) {
  ex = ex.error;
} else if (message && utils.isErrorEvent(message)) {
  ex = message.error;
}

@michal-rumanek
Copy link

I think it's necessary, e.g. for the case when more than one Sentry global error handlers are installed (Raven.install()).
@kamilogorek what do you think?

@kamilogorek
Copy link
Contributor

Good catch @michal-rumanek, we indeed shouldn't modify that's passed down to other handlers.

We also don't need to double check here:

if (ex && utils.isErrorEvent(ex)) {
  ex = ex.error;
} 

if (message && utils.isErrorEvent(message)) {
  message = message.message;
}

and we can write it like this instead

if (utils.isErrorEvent(ex)) ex = ex.error;
if (utils.isErrorEvent(message)) message = message.message;

as passing undefined to utils.isErrorEvent won't do any harm.

@shcallaway
Copy link
Contributor Author

shcallaway commented Dec 7, 2017

@michal-rumanek @kamilogorek I disagree about passing the original message to _oldOnerrorHandler. Clearly, the original developer assumed that message would be a string. Otherwise, this [object ErrorEvent] bug would not exist. So it makes sense to pass the string to _oldOnerrorHandler rather than the ErrorEvent.

@shcallaway
Copy link
Contributor Author

@kamilogorek @michal-rumanek Can I get some feedback on this? My team can't use Sentry until we start seeing real errors instead of ErrorEvents.

@kamilogorek
Copy link
Contributor

@shcallaway thanks for your patience, I was working on getsentry/sentry#6709 for last few days and had to move SDK aside for a while.

Let's get it merged asap.

Clearly, the original developer assumed that message would be a string.

But what if the original developer already handled (or uses a solution that does that) case like this? We'd change expected (well, not so expected :P) behaviour.

@kamilogorek
Copy link
Contributor

@shcallaway I asked other devs and we'd prefer to stick with original arguments.
Can you please change it so that we can merge it Today? :)

@kamilogorek
Copy link
Contributor

Fixed it myself, rebased and merged manually. Preserving correct author info of course :) 315dab5

Thanks for contributing!

@kamilogorek
Copy link
Contributor

Released in 3.21.0

@shcallaway
Copy link
Contributor Author

You’re the best. Thanks!

@michal-rumanek
Copy link

Thank you!

@shcallaway shcallaway deleted the bug/error-event-trace-kit branch December 19, 2017 21:31
@shcallaway shcallaway restored the bug/error-event-trace-kit branch December 19, 2017 21:31
@enapupe
Copy link

enapupe commented Jul 5, 2018

Hey guys, after seeing the linked issue (#1008) I updated my raven version but I'm still receiving error reports as [object ErrorEvent]. The relevant info:

name Chrome
version 67.0.3396
Name raven-js
Version 3.26.3

And my code looks something like:

const handleWindowError = (event) => {
  window.Raven.captureException(event, {
    extra: { state: toJSONable(store.getState()) },
  })
}
window.addEventListener('error', handleWindowError)

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.

Error message property logged as [object ErrorEvent]
4 participants