Skip to content

Stack trace lost when capturing DOMException #4085

Description

@nowylie

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node(raven for node)
  • other:

Version:

6.13.3

Description

This is related to #3119

When calling captureException with a DOMException the stack trace of the error is lost.

The code at line 76 of eventbuilder.ts currently has a comment:

if(isDOMError(exceptionasDOMError)||isDOMException(exceptionasDOMException)){// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)// then we just extract the name, code, and message, as they don't provide anything else// https://developer.mozilla.org/en-US/docs/Web/API/DOMError// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
...

Which I believe is incorrect. DOMError is a legacy API but I don't believe DOMException is. According to 3.14.1. DOMException custom bindings it is expected that DOMException should be an instance of Error and have an associated stack trace. I have confirmed that this is the case in current versions of Safari/Edge/Firefox/Chrome. This is not the case in IE11 though.

I am happy to submit a PR to fix this issue but wanted to get some guidance first.

The fixes I've considered so far are:

  • Remove the isDOMException check from the above line, but this will not catch DOMExceptions in IE11 (or any other platform where they're not instances of Error).
  • Move the if (isError(exception as Error)) block before the other checks and remove the case '[object DOMException]': from isError. However I'm not sure where else isError is used or what the expected behaviour of this function is.
  • Change the condition on line 76 from ... || isDOMException(exception as DOMException) to ... || (isDOMException(exception as DOMException) && !isInstanceOf(exception, Error)).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions