-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add the ability to handle caught async exceptions in zones #15105
Copy link
Copy link
Closed
Labels
P1A high priority bug; for example, a single project is unusable or has many test failuresA high priority bug; for example, a single project is unusable or has many test failuresarea-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-asynctype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Milestone
Metadata
Metadata
Assignees
Labels
P1A high priority bug; for example, a single project is unusable or has many test failuresA high priority bug; for example, a single project is unusable or has many test failuresarea-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-asynctype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Type
Fields
Give feedbackNo fields configured for issues without a type.
Right now there are only two ways to use a ZoneSpecification to interact with exceptions: [handleUncaughtError], which is passed the error when it would leave the zone; and [registerCallback] et al, which can wrap the callback in a try/catch block to capture exceptions that are raised.
I'm trying to implement a solution to issue #7040 using zones (as suggested on that bug), and I'm finding that these two methods of interacting with exceptions aren't sufficient. When tracking the stack traces that are relevant to a given exception, it's important to know the context at the exact point in time the exception is signaled. We can do this to some extent using [registerCallback] and try/catch, but this provides no visibility into exceptions reported using e.g. [Completer.completeError].
Here's a straw-man proposal: ZoneSpecification.registerErrorHandler takes the same arguments as HandleUncaughtErrorHandler and returns something like the internal _AsyncError type -- an error/stack-trace pair. It's called whenever an exception reaches dart:async, either by being thrown or passed explicitly using [Completer.completeError] or similar. The return value is used as the error that's saved and propagated, or passed to [handleUncaughtError].
In addition to supporting issue #7040, this would make it easy to e.g. write code to detect places where errors are thrown without stack traces, or even to automatically add stack traces.