-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
isError
returns false
for DOMException
instances
#2
Comments
Given that it's bizarre to even have DOMException in node, and given that there's just no way to robustly detect it, I don't think that's a case worth worrying about (however, you may want to file it as a bug in node for |
IMO it's bizarre to have const ac = new AbortController()
ac.abort()
ac.signal.reason instanceof DOMException // true |
yeah, that's part of the weirdness of AbortController, via fetch - it should never have been a DOMException. Unless node offers a way to robustly identify it, though, I'm not sure if we should do anything for it. |
I don't think it's particularly to do with Other non-DOM-related and non-fetch-related APIs also produce
|
I'm just talking about the history - Abort things were built to provide cancellation to fetch, initially. That there are many other use cases is why using DOMException made no sense. Similarly, anything that's not DOM-related simply shouldn't be throwing an error named "DOM" ¯\_(ツ)_/¯ but that ship has sailed. Regardless of what the behavior is here, I'd love to add test cases for all of those if you want to submit a PR. |
isError
returnsfalse
forDOMException
instances.From what I can see, there are three reasons for this:
Error.isError/implementation.js
Lines 22 to 24 in 059b44a
In NodeJS,
require('util').types.isNativeError(new DOMException())
givesfalse
.Error.isError/implementation.js
Lines 26 to 28 in 059b44a
In current server-side implementations (pending whatwg/webidl#1421),
structuredClone(new DOMException())
returns{}
, i.e. a plain JS object.Error.isError/implementation.js
Lines 34 to 37 in 059b44a
Even if this line was hit (which it won't be because the previous two lines would both return early with
false
),Symbol.toStringTag in new DOMException()
returnstrue
, so the condition fails.It doesn't seem there's any 100% foolproof way of detecting
DOMException
s until whatwg/webidl#1421 lands in implementations, so you could either:Symbol.toStringTag
tag specifically in the case ofDOMException
*, which would fail onDOMException
s with spoofedtoStringTag
or other objects withtoStringTag
spoofed as "DOMException"instanceof
checking specifically in the case ofDOMException
*, which would fail on cross-realmDOMException
s. I guess this can't be tested for in Node asrequire('vm').runInNewContext('new DOMException()')
givesDOMException is not defined
, but such cross-realmDOMException
s are presumably pretty commonplace in browsers (e.g. anyDOMException
originating from aniframe
)* and maybe
DOMError
and/orException
too?The text was updated successfully, but these errors were encountered: