-
Notifications
You must be signed in to change notification settings - Fork 295
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
Expose signal.reason
as error.cause
for AbortError
#1090
Comments
The discussion that introduced this feature goes into this. It's essentially a way to signal an exception. If you want to say it's an "AbortError" DOMException and provide additional data, you'd have to annotate that exception object with that data and signal with that. It's a bit unfortunate that the Fetch integration isn't complete yet. I've added a comment to whatwg/fetch#1343 to help speed that along. |
The whatwg/fetch#1343 seems to be going in the direction of aborting with the reason from the signal, but this PR is suggesting instead to abort with an I've been searching for several hours through issues and don't see a resolution anywhere that's being consistently applied across environments. Node.js seems to have consistently opted for using I can understand both perspectives. However, one aspect of the |
#1027 is where we decided on the design. And that mirrors whatwg/streams#1165 (comment). At least @jasnell was involved on behalf of Node.js. I don't know where |
From reading through the referred issues, I don't really see any exact arguments against using During that time, error cause proposal was at Stage 3 so it's natural that it wasn't used in prior standards. It is also natural to keep consistent behavior between subsystems (hence why it's a
This is somewhat possible if we call
Apparently there is an issue with Node.js perspective and very similar concerns: #1033.
Yes, good idea. |
The error cause proposal is archived. I don't see |
20.5.1.1 |
Ah, whatwg/webidl#969 tracks adding @domenic any thoughts on this? |
Not really, I think you covered it! IMO this and #1033 should be closed. |
Thank you. I had forgotten about #1033. I think this issue is actually a duplicate of that. I'm looking for implementation guidance for APIs that use |
Thanks, this is a duplicate of #1033. |
Current situation with
AbortSignal
aborting looks confusing.As an user, I want to handle
err
and know what happened. There are three main possibilities:AbortError
: in case of more complicated code, a manual/conditional cancellationTimeoutError
: standardized timeoutfetch
in this caseIn current implementations (Chrome 103.x, Firefox 101.x, node 18.x),
err
is anAbortError
. There's no way to know it's a timeout, nor to retrievesignal.reason
if any.From my understanding of current specs and plans on applying them to
fetch
in particular,err
should be thesignal.reason
itself:TimeoutError
in this example or arbitrary non-undefined value in general."Current" version has an obvious issue: we can't distinguish timeout from manual abortion, and can't distinguish different abortion reasons.
"Future" version has another issue: it breaks backwards compatibility with userland code that relied on
AbortError
, and more importantly, disallows us to distinguish abortion errors from everything else.With Error Cause proposal being included in ES2022, it became possible to chain errors. It sounds perfectly reasonable to me if functions aborted by
AbortSignal
will always throw an abortion caused by signal, i.e.AbortError
havingsignal.reason
in itscause
property.err?.name === 'AbortError'
robustnessTimeoutError
, will be still recognized as abortsIs there anything that makes this concept impossible or unwanted?
The text was updated successfully, but these errors were encountered: