-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Provide an onError handler that will crash the app #11206
Description
The default onError handler dumps the error to the console. On release builds, it's very likely that an uncaught exception leaves the app in an unusable/unpredictable state. In such cases, it's common for the app developer to prefer that the app crashes rather than it continue in such a state. Crashing the app also triggers existing flows like built-in crash reporting.
The developer can currently stop the app by calling exit([int code]) from dart:io, but doing so looks like a "clean exit" to the OS, even if a non-zero exit code was used. Rather, we want to trigger an exit that the OS will detect as a crash, with associated error data.
I suggest we add support for an onError handler that will crash the app in such a way as to tie the uncaught Dart exception to the crash.
I see two possible ways to accomplish this:
- Via a
CrashOnDartExceptionPluginthat would setonErrorto a handler that forwards the exception to the OEM code via our message passing bus, at which point the OEM code would crash the app. - We provide a
crash([FlutterErrorDetails details])method that app developers could set as theonErrorhandler. The implementation would probably use the same mechanics as option 1, but using built-inSystemChannels.X.
I think option 2 is probably the way to go.