dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.07k stars 1.56k forks source link

"Stop on uncaught exceptions" sometimes stops on caught exceptions #55664

Closed lukehutch closed 4 months ago

lukehutch commented 4 months ago

If I have "[Stop on] Uncaught exceptions" checked in VS Code, sometimes the debugger will stop when an exception is obviously caught, if there is an async gap between the try-catch and where the exception is thrown:

Example: await client.openStreamingConnection is clearly within a try-catch block, yet the runtime reports that the exception is unhandled, and the debugger stops on the exception as uncaught.

image

Workspace Environment ```text Dart Code extension: 3.89.20240501 Flutter extension: 3.89.20240501 (activated) App: Visual Studio Code App Host: desktop Version: linux 1.89.0 Workspace type: Dart, Flutter (LSP) (Multiroot) Dart (3.5.0-131.0.dev): /opt/flutter/bin/cache/dart-sdk Flutter (3.22.0-23.0.pre.43): /opt/flutter (Pixel 7 Pro (android-arm64/android)) ```
Output from 'dart info' `/opt/flutter/bin/cache/dart-sdk/bin/dart info` If providing this information as part of reporting a bug, please review the information below to ensure it only contains things you're comfortable posting publicly. #### General info - Dart 3.5.0-131.0.dev (dev) (Fri May 3 09:02:58 2024 -0700) on "linux_x64" - on linux / Linux 6.8.8-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Apr 27 17:42:13 UTC 2024 - locale is en_US.utf8 #### Project info - sdk constraint: '>=3.1.5' - dependencies: auto_size_text, boxy, bubble, cached_network_image, carousel_slider, chat_message_timestamp, collection, cronet_http, cross_file, cupertino_http, cupertino_icons, dart_emoji, delayed_display, device_info_plus, dio, dio_smart_retry, email_validator, exif, extended_image, file_picker, flutter, flutter_cache_manager, flutter_email_sender, flutter_google_maps_webservices, flutter_image_utilities, flutter_localizations, flutter_persistent_value_notifier, flutter_staggered_grid_view, flutter_svg, flutter_value_notifier_stateful_widget, fluttericon, fluttertoast, geocoding, geolocator, google_fonts, google_maps_flutter, google_maps_webapi, google_places_flutter, http, image_crop, image_picker, image_picker_android, image_picker_platform_interface, intl, jiffy, keep_keyboard_popup_menu, latlong2, line_awesome_flutter, logging, maps_launcher, material_dialogs, package_info_plus, path_provider, persistent_bottom_nav_bar_v2, pexels_api, pinch_to_zoom_scrollable, provider, serverpod_auth_apple_flutter, serverpod_auth_client, serverpod_auth_facebook_flutter, serverpod_auth_google_flutter, serverpod_auth_shared_flutter, serverpod_client, serverpod_flutter, serverpod_serialization, share_plus, shared_preferences, syncfusion_flutter_datepicker, timezone, url_launcher - dev_dependencies: flutter_launcher_icons, flutter_lints, flutter_test, lints - elided dependencies: 1 #### Process info | Memory | CPU | Elapsed time | Command line | | ------: | ---: | -----------: | ------------------------------------------------------------------------------------------ | | 69 MB | 0.0% | 14:30 | dart devtools --machine --allow-embedding --dtd-uri ws:/9EChvxoYXkiWK34D | | 70 MB | 0.0% | 14:32 | dart devtools --machine --allow-embedding --dtd-uri ws:/pquPWF3bHj8KzNfj | | 1392 MB | 4.7% | 14:33 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.89.20240501 | | 1084 MB | 2.2% | 14:31 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.89.20240501 | | 75 MB | 0.0% | 14:33 | dart tooling-daemon --machine | | 76 MB | 0.0% | 14:31 | dart tooling-daemon --machine | | 81 MB | 0.2% | 14:33 | flutter_tools.snapshot daemon | | 82 MB | 0.2% | 14:31 | flutter_tools.snapshot daemon | | 77 MB | 0.2% | 08:33 | flutter_tools.snapshot debug_adapter | | 341 MB | 0.8% | 08:32 | flutter_tools.snapshot run --machine --start-paused -d 29161FDH300BLP --devtools-server-address http:/ --target /main.dart |
Output from 'flutter doctor' `/opt/flutter/bin/flutter doctor -v` ```text [✓] Flutter (Channel master, 3.22.0-23.0.pre.43, on Fedora Linux 39 (Workstation Edition) 6.8.8-200.fc39.x86_64, locale en_US.utf8) • Flutter version 3.22.0-23.0.pre.43 on channel master at /opt/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b8abc10689 (2 days ago), 2024-05-05 13:01:23 -0400 • Engine revision 624dcb987f • Dart version 3.5.0 (build 3.5.0-131.0.dev) • DevTools version 2.35.0 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /home/luke/Android/Sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /opt/android-studio/jbr/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at google-chrome [✓] Linux toolchain - develop for Linux desktop • clang version 17.0.6 (Fedora 17.0.6-2.fc39) • cmake version 3.27.7 • ninja version 1.11.1 • pkg-config version 1.9.5 [!] Android Studio (version unknown) • Android Studio at /opt/android-studio • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart ✗ Unable to determine Android Studio version. • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) [✓] VS Code (version 1.89.0) • VS Code at /usr/share/code • Flutter extension version 3.89.20240501 [✓] VS Code (version 1.90.0-insider) • VS Code at /usr/share/code-insiders • Flutter extension version 3.79.20231130 [✓] Connected device (3 available) • Pixel 7 Pro (mobile) • 29161FDH300BLP • android-arm64 • Android 14 (API 34) • Linux (desktop) • linux • linux-x64 • Fedora Linux 39 (Workstation Edition) 6.8.8-200.fc39.x86_64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.118 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
lukehutch commented 4 months ago

There is also a rethrow involved, which may cause the problem:

image

mraleph commented 4 months ago

We would need a reproduction of the behavior you are seeing or at least more code pasted as text with clear description of what is happening. (e.g. here is the code in each frame on the stack, here is where exception is thrown, here is where debugger has stopped, etc).

mraleph commented 4 months ago

FWIW I can also see that exception is reported to the console as unhandled. So if that's the same exception the debugger stops for then debugger is correct.

lukehutch commented 4 months ago

I spent considerable time trying to debug this, but couldn't follow the logic in this callback-based code. There are all sorts of weird (primitive Dart) conventions like capturing a stacktrace anywhere you think you may asynchronously throw an error in future, and then passing it into the async call...

I'll close this since I couldn't figure it out!