-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
Exclude AbortError
from unhandled rejections?
#40120
Comments
(I have not made up my mind yet regarding this being a good/bad idea) |
There was an attempt made in this direction, but it didn't go well in tc39 https://github.com/tc39/proposal-cancelable-promises/tree/0e769fda8e16bff0feffe964fddc43dcd86668ba. I haven't used |
Yes, that was the reference. I was very much in favour of that effort back then :)
Unlike browsers - Node.js servers crash on uncaught exceptions (and unhandled rejections) to prevent cascading failures - in the browser this being uncaught isn't a big deal because in browsers Intuitively - |
I don't have a clear opinion on this topic yet, but I feel like if we add a mechanism that allows to opt out of unhandled rejections for some classes, it should be public API and not only available through AbortError |
It could be a symbol for example or a brand/utility. Though I think we're mostly missing someone with a strong opinion to say "this is a good/bad idea" now. I'll ping some friends who work on other platforms and ask. |
I don't think this is going to improve the developer experience of Node.js. What would be a code example that would benefit from |
@mcollina good question, I think a lot of people use
It's quite a specific case but one that happened to me in the past. If I think a case where ignoring them is unsafe would settle this (in my book) towards not treating them differently. Better to wake up someone in the middle of the night and not fail catastrophically and the workaround of filtering yourself in a |
Can you make an example for this? Either some code handles error or they don't. How could they handle every other cases but not those? |
Not handling a rejection isn’t an error either, so i don’t see why abort errors would be special. |
Didn't we change this semi recently? I remember we had a vote and everything. |
@ronag a vote decides what node does, it doesn't change what the semantics of the language are intended to be. There are no kinds of errors that the uncaught error listener treats specially, why should there be any kind of rejections that the unhandled rejection handler treats specially? |
I'm confused. I was just referring to your statement |
@ronag ah, sorry for the confusion. what i mean is, The OP says:
and that seems to be discussing conceptual errors, so I was pointing out that no unhandled rejections are inherently conceptual errors. |
I have a related issue for Chrome Devtools, as in the browser one can just attach a Node can't really do this though, I had an issue on Node to add a capability similar, but it doesn't sound like it would be compatible with Node's event model.
Just from a quick look of some other languages, C# and Java both have some form of AbortException, these bubble up the stack per normal and need to be caught. I'm not entirely sure for C# and Java, but Python is similar and throws a import asyncio
async def forever():
try:
while True:
await asyncio.sleep(1)
print("Tick")
except CancelledException:
print("I saw cancellation")
# We reraise the cancellation to propagate it up
# Note that if you raise a different error here
# it does get thrown in main()
raise
async def main():
task = asyncio.create_task(forever())
await asyncio.sleep(5)
# This doesn't throw an error, it only affects the stack within
# the task that is run
task.cancel()
asyncio.run(main()) This asynchronous stack stuff would be rather nice in JS, however it essentially Zones which have been rejected as TC39 before. |
@ronag note that @ljharb's interpretation of what the language says is nuanced. The language does not specify what the host should do on unhandled rejections or uncaught exceptions - that is left to host-hooks to decide (e.g. HostPromiseRejectionTracker - 25.6.1.9 in the spec). Different platforms (e.g. Node.js and the browser) do different things here because of different requirements (ux in browsers means errors just get logged, safety in Node.js means the process aborts). The fact the language does not treat unhandled rejections in a certain way isn't evidence towards how Node.js should behave - it just means the language doesn't see it as its business to define these semantics - probably since it couldn't do so well given conflicting requirements from implementors. |
Note that both:
|
@benjamingr you are completely correct that the only reason the spec doesn't explicitly ban what node is doing, is because nobody can figure out how to write the spec text that would ban it. The intent, however, is as I've stated (unhandled rejection hooks were added to the spec solely motivated by browsers being able to log unhandled rejections to the console), and node is violating the intent regardless of what loopholes the spec currently has. Either way, uncaught errors are all treated the same in node, so I fail to see why it would make sense to treat any uncaught rejection differently from another. |
I am happy we agree that the spec does not prohibit or express an opinion on what runtimes do on unhandled rejections or uncaught exceptions. I personally think it would be unfortunate if it did since different runtimes have different requirements and needs.
I... don't believe that is the case? I mean, I can link to some 2014 esdiscuss posts discussing other cases - but honestly that is irrelevant I think? The spec is a formal document - Node.js agrees to conform to the spec - Node conforms to the spec either way. Anything that is "host environment" and not language related is mostly Node's purview.
That's a good point. I'm... not sure. I think it's probably one of those cases where there are compelling arguments but the complexity of having an inconsistent API outweigh the benefits. I'll go ahead and agree with the opinions expressed and close this in the meantime. Feel free to reopen if you want to bring it up again :) |
Hey, following a few discussions here tc39/proposal-cancellation#22 I'm wondering if
AbortError
should be excluded from generating anunhandledRejection
. Aborting things isn't really an error (it's best effort) and the fact it's even an error and not a third-state runningfinally
clauses only is unforunate.In addition there are several places we (and DOM APIs) already silently remove handlers without rejecting anything with an
AbortError
when an AbortSignal is aborted.@ronag @jasnell @mcollina @jakearchibald @ljharb @Linkgoron
The text was updated successfully, but these errors were encountered: