Skip to content

Rethrow logic adds an extra stacktrace line which causes culprit to be set to raven.js #300

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

Closed
tgr opened this issue Dec 15, 2014 · 3 comments

Comments

@tgr
Copy link

tgr commented Dec 15, 2014

Steps to reproduce:

  • install raven.js 1.1.16 with jQuery integration
  • configure it to catch global errors via window.onerror
  • throw an error in a function that gets wrapped (in my case, it was something called from a $.ready handler) and do not catch it manually

Expected result: culprit is the function which throws the error
Actual result: culprit is raven.js

Raw stack trace looks like this:

Stacktrace (most recent call first):

  at ? (/w/extensions/Sentry/resources/raven/raven.js:1282)
  at MultimediaViewer.MMVP.loadImage (/w/extensions/MultimediaViewer/resources/mmv/mmv.js:255:22)
  at Object.<anonymous> (/w/extensions/MultimediaViewer/resources/mmv/mmv.js:346:12)
  at Function.jQuery.extend.each (/w/load.php:383:23)
  at MultimediaViewer.MMVP.loadImageByTitle (/w/extensions/MultimediaViewer/resources/mmv/mmv.js:344:5)
  at Object.<anonymous> (/w/extensions/MultimediaViewer/resources/mmv/mmv.bootstrap.js:366:11)
  at Object.<anonymous> (/w/load.php:3276:33)
  at fire (/w/load.php:3119:30)
  at Object.self.fireWith [as resolveWith] (/w/load.php:3231:7)
  at MultimediaViewerBootstrap.MMVB.isCSSReady (/w/extensions/MultimediaViewer/resources/mmv/mmv.bootstrap.js:135:13)

Sentry report is at http://sentry-beta.wmflabs.org/jserrors/jserrors/group/14/

What seems to happen is that the wrapper rethrows the exception (this is line 195 of wrapped() in Raven.wrap()), that causes an extra line to be added to the stacktrace, and that line gets identified as the culprit.

This seems to be the combination of two bugs:

  • raven.js not ignoring its own functions in the stack trace (If raven is the culprit, ignore that frame #200)
  • the throw command gets added to the top of the stack, even though the exception is logged before it is rethrown. I suppose this is due to the TraceKit trickery of re-reporting the exception from the onerror handler to get more details in IE, but that should be completely unnecessary here (I was testing in Chrome 39).
@mattrobenolt
Copy link
Contributor

I assume #200 would solve this as well, right? Since we'd just shift everything down the stack.

@tgr
Copy link
Author

tgr commented Dec 16, 2014

In most cases, it would. I am experimenting with using Sentry in an environment where all scripts get minified and bundled together, so I don't think there is any way to guess whether something is inside raven.js just from the stack trace (although that might depend on the browser, e.g. Chrome's stack trace API seems to provide direct access to the function objects in the stack so it could easily identify a custom function).

I guess the solution to that could be source maps and overriding the culprit on the server side.

tgr added a commit to tgr/raven-js that referenced this issue Feb 24, 2015
* Remove exception rethrowing from TraceKit.report. Raven would catch
  them again so it is pointless, and it can pollute the stack trace
  (since TraceKit doesn't extract information from it immediately,
  only after the rethrow has happened, adding another call to the
  top of the stack).
* Update jsdoc TraceKit.repoer to make clear that additional arguments
  are passed to the handlers.
* Remove the try-catch in Raven.captureException that was made
  unnecessary by the change.

Fixes getsentry#300.
@mattrobenolt
Copy link
Contributor

This should be irrelevant now as well.

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 a pull request may close this issue.

2 participants