-
Notifications
You must be signed in to change notification settings - Fork 568
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
exceptions thrown by Flutter apps end up displayed on the console via dartPrint
instead of window.oneerror
#3148
Comments
… in the console based on the error state of the app
DartPad's error handling has been problematic because the framework intercepts all errors and reports them to the JS console as normal console output. I'm able to make
I think the best way to solve this would be to configure the Flutter engine to report errors differently. @ditman do you know if there's a way to configure how errors are reported on the web? |
As @parlough pointed out, we already wrap the user's main so it should be easy to add this code to all DartPad scripts |
would that work for Dart, too, or just Flutter? |
Dart scripts currently report errors correctly, no? |
no |
I was able to make frame.dart receive a stderr type in a Flutter app using a normal Dart script, could you share more details? |
you're right, @johnpryan. my initial testing showed that unhandled exceptions from both Dart and Flutter resulted in a message not routed to stderr but now that's only true for Flutter; unhandled Dart exceptions do end up in stderr output. And it's pretty great that only a single LOC in the Flutter void main() {
FlutterError.onError = (err) => throw err;
run(...);
}
... if we could inject this single LOC, we'd be able to properly detect a console that contains text associated with errors and then properly enable the Suggest Fix feature. I know you're working on this issue; once it's handled, I'll fix the Suggest Fix problem. |
What happened?
I'm trying to add a feature to the console that only shows itself when there's an error in the console and not just someone calling
print
. I'm using the_consoleShowingError
field of theAppModel
, which is set when there's an exception message posted from the iframe hosting the app. Unfortunately, as far as I can tell, the_consoleShowingError
flag is never set, because the JSwindow.onerror
handler defined inframe.dart
is never called. Instead, where there's an error in the app being hosted in DartPad, it's routedFlutterError.reportError
for Flutter apps and to something else (haven't figured out what) for Dart apps. This handler in turn routes the exception message through thedartPrint
method (also defined inframe.dart
) in the same way that a call toprint
works. The exception ends up in the console but there's no way to tell that message from a call toprint
.Steps to reproduce problem
throw 'oops'
call to your program, making sure not to wrap it in a try-catch block._initListener
function inframe.dart
withdata['type']
set to 'stdout' (set by thedartPrint
function) instead of 'stderr' (set by thewindow.onerror
) handler.There still needs to be some work to set
_consoleShowingError
totrue
when a message withdata['type']
set tostderr
is handled, but that work can't happen with exceptions andprint
calls both routing todartPrint
.Additional info
Browser
Browser: Chrome
Version: 133.0.6943.55 (Official Build) (arm64)
Are you using any extensions/plugins that affect website behavior
(particularly those that affect iframes, such as ad blockers)?
None I can think of.
Are there any warnings or errors in your browser's JavaScript console?
If so, paste them below:
None that seem to have any bearing.
Machine
Operating system: macOS
Version: 15.3 (24D60)
Your code
What code was in the editor, if any, when the failure occurred? You
can paste it in below:
DartPad's output
Did DartPad print anything to the console pane? If so, paste it below:
If you were running Flutter code, you can also paste an image of the
Flutter output directly into this bug report.
n/a
The text was updated successfully, but these errors were encountered: