Skip to content

Debugging in VS Code throws uncaught exceptions #47692

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

Closed
a7md0 opened this issue Nov 13, 2021 · 7 comments
Closed

Debugging in VS Code throws uncaught exceptions #47692

a7md0 opened this issue Nov 13, 2021 · 7 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@a7md0
Copy link

a7md0 commented Nov 13, 2021

I'm not sure if this is the right place to file this issue, but this is related to #37953. The reproduction repository is provided, which uses 3rd party HTTP client package (flutterchina/dio). To recap, awaiting a Future that may fail from the library (e.g., 404 HTTP GET request) will throw an uncaught exception, even though the call is surrounded with try/catch block (the catch block get executed directly after skipping the uncaught exception).

Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git  
Framework • revision 18116933e7 (4 weeks ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4
  • Platform: Windows 10 x64 with Android Simulator (API 29)
  • Breakpoints from "Run and Debug" tab
    image
@mkustermann mkustermann added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 15, 2021
@mkustermann mkustermann assigned ghost Nov 15, 2021
@mkustermann
Copy link
Member

@cskau-g Could you take a look at this? (Related to the break in debugger on unhandled exceptions feature you were implementing)

@a7md0
Copy link
Author

a7md0 commented Nov 15, 2021

There has been an new release for the package with the following PR cfug/dio#1317 (version 4.0.2), which resolved the unhandled exception for me while debugging. Not sure if this was expected from the package itself or its should be investigated more

@ghost
Copy link

ghost commented Nov 26, 2021

@a7md0 I think I may have initially misunderstood what you're reporting, but correct me if I'm wrong here:

The code in the linked repo. does in fact correctly catch the expected error in the catch block here:
https://github.com/a7md0/ex_unhandled_app/blob/main/lib/main.dart#L51-L55

Rather, the actual issue you're reporting is that your Dio.get(..) triggers a separate uncaught exception from:
https://github.com/a7md0/ex_unhandled_app/blob/main/lib/main.dart#L43-L45

Which is thrown from here:
https://github.com/flutterchina/dio/blob/71b38981bb78e4506dca577fa42d92af4296f496/dio/lib/src/dio_mixin.dart#L678
Which in turn is called from here:
https://github.com/flutterchina/dio/blob/71b38981bb78e4506dca577fa42d92af4296f496/dio/lib/src/dio_mixin.dart#L585-L590

This is however working as intended.

The offending code in dio/lib/src/dio_mixin.dart is:

      _dispatchRequest(reqOpt).then(...);

The call to Future<...> _dispatchRequest<T>(...) async { .. }, as we can see, returns a Future which the caller is expected to either 1) await, or 2) pass on (e.g. return) for someone else to await.
If this does not happen, you have an unawaited future, which may indeed throw uncaught exceptions.

The reason cfug/dio#1317 changes this behaviour is that while it's still an unawaited future, they now attach an error handler to it, meaning the exception is no longer uncaught.

@ghost ghost closed this as completed Nov 26, 2021
@mkustermann
Copy link
Member

@cskau-g Thanks for investigating!

@markfili
Copy link

markfili commented Nov 26, 2021 via email

@ghost
Copy link

ghost commented Nov 26, 2021

@markfili, if you're asking for a way to disable stops on uncaught exceptions, then that already exists as you can use e.g. DevTools to toggle the debugger behaviour for exceptions (stop on none, uncaught, or all) through the service protocol.

Whether this is exposed in your IDE of choice is of course up to the IDE/extension authors.

If you want more granular control, to set the behaviour per library, then I think that's a feature request for service protocol. (Please file a separate issue for that.)
Though I personally think being able to disable per library won't be that much more useful - libraries shouldn't be throwing large amounts of uncaught exceptions in the first place.

@aliyazdi75
Copy link

Hi @cskau-g,

Regarding this issue for cached_network_image plugin, this problem still persists.

This is a reproducible Gist. As you can see, with defining an errorWidget, the exceptions should be handled but the debugger throws on cached_network_image exceptions only, not all flutter exceptions.

Could you please take a look at this if possible?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants