-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: DOMException
missing from “Errors” API reference docs page
#40789
Comments
Yes, this is a good catch, we need to document |
What is the actual reason behind throwing a |
It makes it easier to write code that works on both browsers and Node.js – so if you want to check if the caught exception you just get is an
FWIW none of Node.js errors is using this pattern.
Note sure what you mean here, Node.js will adopt the same APIs as browsers wherever it makes sense to do so (including errors), but both browsers and Node.js are already using the same |
FWIW we do use an For DOM APIs (e.g. |
@aduh95 From the docs
Which doesn't fully apply here, but good to know that const { equal } = require('node:assert');
const { isNativeError } = require('node:util/types');
const ac = new AbortController();
ac.abort();
try {
ac.signal.throwIfAborted();
} catch (err) {
console.log(isNativeError(err)); // false
console.log(err instanceof Error); // true
console.log(isNativeError(new Error())); // true
console.log(typeof err.code, err.code); // number 20
}
try {
equal(1, 2);
} catch (err) {
console.log(typeof err.code, err.code); // string ERR_ASSERTION
} |
Note that when calling Node.js specific APIs that deal with aborted signals will use a native error with code $ node -e 'events.once(global, "event", {signal:AbortSignal.abort()}).catch(e=>console.log(e.code, require("node:util/types").isNativeError(e)))'
ABORT_ERR true |
@aduh95 Which means I should check for both try {
AbortSignal.abort().throwIfAborted();
} catch (err) {
console.log(typeof err.code, err.code); // number 20
} |
Or you could check
It's not a global event, I've used Note that try {
AbortSignal.abort(null).throwIfAborted();
} catch (err) {
console.log(err); // null
}
try {
AbortSignal.abort('reason').throwIfAborted();
} catch (err) {
console.log(err); // "reason"
}
// Using an aborted signal with the string "reason" as the reason:
require('node:events').once({}, '', {signal:AbortSignal.abort('reason')})
.catch(err => {
console.log(err.code); // ABORT_ERR
console.log(typeof err.cause, err.cause); // string reason
});
// Using an aborted signal no explicit reason:
require('node:events').once({}, '', {signal:AbortSignal.abort()})
.catch(err => {
console.log(err.code); // ABORT_ERR
console.log(typeof err.cause); // object
console.log(err.cause?.code); // number 20
console.log(err.cause?.name); // AbortError
}) |
@aduh95 I see that Node wraps DOM's AbortError into Node's AbortError. If I manually call
Thanks for the help! Also Node's message says |
Good catch :) AFAIK the spec doesn't have any requirement for the error message, so I don't think it's a problem if those differ. FWIW it seems that all runtimes differ:
|
There's no practical way. We wouldn't want to expose something like that in a Node.js specific way, we would want to either have it added to the ECMAScript spec, or at least have the WinterCG discuss how it can be exposed in a way that maximize code portability. |
📗 API Reference Docs Problem
errors
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
DOMException
, which was made globally available in v17.0.0, is not amongst the runtime errors listed in our “Errors” API reference docs.It is, however, correctly listed on the “Globals” page.
By referencing the original (“Globals”) location from a brand new section dedicated to
DOMException
on our “Errors” page, I am thinking that we may be able to have it listed on both pages similar to how we listAssertionError
on both/api/errors.html
and/api/assert.html
. Thoughts?P.S. Unsure of how relevant this may be (perhaps wrt the potential misclassification of
AbortError
raised in #40692), but this seems worth mentioning in this issue…Along w/
structuredClone
(spec link) — which was also made globally available in v17.0.0 — we appear to have added our first (?) couple of objects to be classified as “platform objects” according to Web IDL (at least that’s mine and @domenic’s current interpret of the spec, anyway). Perhaps it may be worth explicitly identifying them as such in our documentation?Any additional information/suggestions would be appreciated. It seems like it could simply be a minor oversight unless I am mistaken.
/cc @aduh95 @targos @Trott @BridgeAR @addaleax @mcollina @benjamingr @jasnell (et al. who may have more context)
submit a pull request.
The text was updated successfully, but these errors were encountered: