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(exception as DOMError) || isDOMException(exception as DOMException)) {
// 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)).
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
This is related to #3119
When calling
captureException
with aDOMException
the stack trace of the error is lost.The code at line 76 of
eventbuilder.ts
currently has a comment:Which I believe is incorrect.
DOMError
is a legacy API but I don't believeDOMException
is. According to 3.14.1. DOMException custom bindings it is expected thatDOMException
should be an instance ofError
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:
isDOMException
check from the above line, but this will not catchDOMException
s in IE11 (or any other platform where they're not instances ofError
).if (isError(exception as Error))
block before the other checks and remove thecase '[object DOMException]':
fromisError
. However I'm not sure where elseisError
is used or what the expected behaviour of this function is.... || isDOMException(exception as DOMException)
to... || (isDOMException(exception as DOMException) && !isInstanceOf(exception, Error))
.