Skip to content

"Global evaluation not currently supported" message is unclear and DAP errors include verbose stack traces #4899

Closed

Description

@lukehutch

Describe the bug

If you try to enter a debug expression when the debugger is not running, you get UnimplementedError, with a big ugly stacktrace. Probably only the error message itself should be shown.

UnimplementedError: Global evaluation not currently supported without a Dart script context
#0      DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:980:7)
#1      BaseDebugAdapter.handle (package:dds/src/dap/base_debug_adapter.dart:141:20)
#2      BaseDebugAdapter.handleIncomingRequest (package:dds/src/dap/base_debug_adapter.dart:460:7)
#3      BaseDebugAdapter._handleIncomingMessage (package:dds/src/dap/base_debug_adapter.dart:301:7)
#4      ByteStreamServerChannel._readMessage (package:dds/src/dap/protocol_stream.dart:82:18)
#5      ByteStreamServerChannel.listen.<anonymous closure> (package:dds/src/dap/protocol_stream.dart:53:24)
#6      _rootRunUnary (dart:async/zone.dart:1407:47)
#7      _CustomZone.runUnary (dart:async/zone.dart:1308:19)
#8      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1217:7)
#9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#10     _DelayedData.perform (dart:async/stream_impl.dart:515:14)
#11     _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
#12     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
#13     _rootRun (dart:async/zone.dart:1391:47)
#14     _CustomZone.run (dart:async/zone.dart:1301:19)
#15     _CustomZone.runGuarded (dart:async/zone.dart:1209:7)
#16     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1249:23)
#17     _rootRun (dart:async/zone.dart:1399:13)
#18     _CustomZone.run (dart:async/zone.dart:1301:19)
#19     _CustomZone.runGuarded (dart:async/zone.dart:1209:7)
#20     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1249:23)
#21     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#22     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#23     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#24     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

To Reproduce
Steps to reproduce the behavior:

  1. Type something into the debug console's input line when the debugger is not running
Workspace Environment
Dart Code extension: 3.79.20231206
Flutter extension: 3.79.20231130 (activated)

App: Visual Studio Code
App Host: desktop
Version: linux 1.85.1

Workspace type: Dart, Flutter (LSP) (Multiroot)

Dart (3.3.0-174.3.beta): /opt/flutter/bin/cache/dart-sdk
Flutter (3.18.0-0.2.pre): /opt/flutter (Chrome (web-javascript/web))

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

Project info

  • sdk constraint: '>=3.1.5 <4.0.0'
  • dependencies: auto_size_text, boxy, cached_network_image, carousel_slider, collection, cross_file, cupertino_icons, device_info_plus, email_validator, exif, extended_image, flutter, flutter_cache_manager, flutter_email_sender, flutter_fgbg, flutter_image_utilities, flutter_localizations, flutter_persistent_value_notifier, flutter_svg, fluttericon, fluttertoast, geocoding, geolocator, getwidget, google_fonts, google_mlkit_face_detection, http, image_picker, intl, jiffy, line_awesome_flutter, logging, material_dialogs, package_info_plus, path_provider, persistent_bottom_nav_bar_v2, provider, random_string, share_plus, shared_preferences, url_launcher
  • dev_dependencies: flutter_launcher_icons, flutter_lints, flutter_test, lints
  • elided dependencies: 11

Process info

Memory CPU Elapsed time Command line
522 MB 0.0% 06:01:35 dart --enable-vm-service=0 --pause_isolates_on_start --disable-dart-dev -DSILENT_VM_SERVICE=true --write-service-info=file:/vm.json --pause_isolates_on_exit --enable-asserts /main.dart
687 MB 1.1% 47:50 dart ../serverpod_cli.dart generate --watch
673 MB 7.1% 07:00 dart ../serverpod_cli.dart generate --watch
75 MB 0.0% 06:01:35 dart debug_adapter
60 MB 0.0% 10:12:55 dart devtools --machine --allow-embedding
59 MB 0.0% 10:12:48 dart devtools --machine --allow-embedding
2172 MB 2.7% 10:12:55 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.79.20231206
1533 MB 0.3% 10:12:48 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.79.20231206
91 MB 0.0% 10:12:55 flutter_tools.snapshot daemon
90 MB 0.0% 10:12:48 flutter_tools.snapshot daemon
Output from 'flutter doctor'

/opt/flutter/bin/flutter doctor -v

[✓] Flutter (Channel beta, 3.18.0-0.2.pre, on Fedora Linux 39 (Workstation Edition) 6.5.12-300.fc39.x86_64, locale en_US.utf8)
    • Flutter version 3.18.0-0.2.pre on channel beta at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fed06b31d9 (3 days ago), 2023-12-13 14:53:33 -0800
    • Engine revision 39c6dc9bdd
    • Dart version 3.3.0 (build 3.3.0-174.3.beta)
    • DevTools version 2.30.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/luke/Android/Sdk
    • Platform android-34, build-tools 33.0.1
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 17.0.4 (Fedora 17.0.4-1.fc39)
    • cmake version 3.27.7
    • ninja version 1.11.1
    • pkg-config version 1.9.5

[✓] Android Studio (version 2022.2)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 73.0.2
    • Dart plugin version 222.4582
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.85.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.79.20231130

[✓] VS Code (version 1.86.0-insider)
    • VS Code at /usr/share/code-insiders
    • Flutter extension version 3.79.20231130

[✓] Connected device (3 available)
    • sdk gphone x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Linux (desktop)            • linux         • linux-x64      • Fedora Linux 39 (Workstation Edition) 6.5.12-300.fc39.x86_64
    • Chrome (web)               • chrome        • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. DanTup commented on Dec 18, 2023

    @DanTup
    Member

    @lukehutch can you clarify what you mean by "when the debugger is not running" here? The error here is coming from the debug adapter, so I wouldn't expect you can trigger this without being in a debug session.

    There is some code to try and provide a context for you to handle this - I wonder whether it's because you don't have any open files or something?

    We should definitely shouldn't show a full stack like this for that error message 😔

  2. added this to the v3.80.0 milestone on Dec 18, 2023
  3. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Dec 18, 2023
  4. DanTup commented on Dec 18, 2023

    @DanTup
    Member

    I can repro this with no open files. Response looks like this:

    {
    	"seq": 44,
    	"type": "response",
    	"body": {
    		"error": {
    			"format": "{message}\n{stack}",
    			"id": 1,
    			"showUser": true,
    			"variables": {
    				"message": "Global evaluation not currently supported without a Dart script context222",
    				"stack": "#0      DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:980:7)\n#1      BaseDebugAdapter.handle (package:dds/src/dap/base_debug_adapter.dart:141:20)\n#2      BaseDebugAdapter.handleIncomingRequest (package:dds/src/dap/base_debug_adapter.dart:465:7)\n#3      BaseDebugAdapter._handleIncomingMessage (package:dds/src/dap/base_debug_adapter.dart:306:7)\n#4      ByteStreamServerChannel._readMessage (package:dds/src/dap/protocol_stream.dart:82:18)\n#5      ByteStreamServerChannel.listen.<anonymous closure> (package:dds/src/dap/protocol_stream.dart:53:24)\n#6      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)\n#7      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)\n#8      _DelayedData.perform (dart:async/stream_impl.dart:515:14)\n#9      _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)\n#10     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)\n#11     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)\n#12     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)\n#13     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)\n#14     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)\n"
    			}
    		}
    	},
    	"command": "evaluate",
    	"message": "Global evaluation not currently supported without a Dart script context222",
    	"request_seq": 7,
    	"success": false
    }
    

    @helin24 I think this started happening with dart-lang/sdk@aa9a219 because of this:

    format: '{message}\n{stack}',
    

    We could change this to:

    format: '{message}',
    

    But it's not clear to me if a) that will break anything for you or b) if it's weird to include the stack inside variables but not use it there.

    Another option could be to not include the stack for DebugAdapterExceptions, or a new sub-class of that designed for user-friendly messages where the stack isn't important (it's not a crash, but an error condition we just want to provide a message for). I don't know what split of the existing DebugAdapterExceptions would go into each camp but I suspect the majority (if not all) are probably intended as user-messages and the stack isn't useful.

  5. helin24 commented on Dec 18, 2023

    @helin24
    Contributor

    @DanTup I looked back at why we made this change initially and I think it will be okay to remove the stack here. Mainly we just wanted to expand body to be an object with id, format, and variables instead of being a string.

  6. lukehutch commented on Dec 18, 2023

    @lukehutch
    Author

    @lukehutch can you clarify what you mean by "when the debugger is not running" here? The error here is coming from the debug adapter, so I wouldn't expect you can trigger this without being in a debug session.

    I can't remember how I triggered this (I think I wasn't running anything at the time, but I can't repro that right now).

    What I can repro right now is that typing anything into the debugging console input line when building an app before launch, or before stopping on a breakpoint after launch, gives this error.

  7. DanTup commented on Dec 19, 2023

    @DanTup
    Member

    @helin24 thanks! I'll leave it in the payload for debugging (since it was in the payload before your change), and just drop it from variables with an appropriate comment.

    @lukehutch I presume your active file is not Dart or you don't have an open file too? The condition for this is basically "we need a thread/frame or a file". You won't have a thread/frame when not paused so it'll try for a file.

    In any case, my fix will make this message clearer and drop the stack:

    image

  8. lukehutch commented on Dec 19, 2023

    @lukehutch
    Author

    @DanTup That message is much better, but I can see there is already an effort to disable the input line when debugging ends. Shouldn't the disablement of the input line prevent that exception from ever being thrown?

    (Sorry, I don't know what you mean by "active file", but it's possible I was viewing something else other than Dart at the time, yes -- I have yaml files in my project)

  9. DanTup commented on Dec 19, 2023

    @DanTup
    Member

    @lukehutch the debug console input box is not available when there is no debug session running (this is VS Code behaviour). For this code to execute, there must be a debug session (VS Code only creates our debug adapter when a debug session starts and terminates it when it ends).

    When there is a running debug session, evaluation is only available when we have one of two things:

    1. An isolate and frame that we can evaluate the expression in (this requires the debugger is paused)
    2. A library to evaluate the expression in (this requires that you have an active open Dart script in the editor, and we will use that)

    So it's very possible to trigger this path by not having any open files and not being paused when you try to evaluate (or, having your only open files by non-Dart files).

  10. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Dec 19, 2023
  11. DanTup commented on Dec 19, 2023

    @DanTup
    Member
  12. DanTup commented on Dec 19, 2023

    @DanTup
    Member

    I tweaked the text slightly to try to make it clearer about having a file open in the editor:

    Evaluation is only supported when the debugger is paused unless you have a Dart file active in the editor

  13. changed the title [-]`UnimplementedError: Global evaluation not currently supported without a Dart script context`[/-] [+]"Global evaluation not currently supported" message is unclear and DAP errors include verbose stack traces[/+] on Dec 19, 2023
  14. lukehutch commented on Dec 19, 2023

    @lukehutch
    Author

    When there is a running debug session, evaluation is only available when we have one of two things:

    1. An isolate and frame that we can evaluate the expression in (this requires the debugger is paused)
    2. A library to evaluate the expression in (this requires that you have an active open Dart script in the editor, and we will use that)

    Well then shouldn't you make it impossible to type into the input field when one or both of those things is not available? This error should never be triggerable.

  15. DanTup commented on Dec 19, 2023

    @DanTup
    Member

    Well then shouldn't you make it impossible to type into the input field when one or both of those things is not available? This error should never be triggerable.

    This is unfortunately not possible. We have no control over this part of the UI in VS Code - the only thing we can do is respond to the "evaluate request" when it's sent to the debug adapter.

  16. lukehutch commented on Dec 20, 2023

    @lukehutch
    Author

    The input field is disabled once a debugging session ends though. Maybe it's worth requesting access to the API that enables or disables this field?

  17. DanTup commented on Dec 20, 2023

    @DanTup
    Member

    The field is disabled by VS Code, it's just based on whether there is a debug session.

    I don't think it's likely we'd ever get APIs to handle this - we'd need more than just the ability to disable the input box - we'd also need access to know if you're paused (which we don't currently). The debug adapter is also running in another process (using a standard protocol that isn't specific to VS Code) so it would only be useful if we're running VS Code-specific code in the client too (in this case we are a little, but it's a workaround for getting the file - there's an open issue about getting a better way to do this at microsoft/vscode#134452).

    So while it's not perfect, I think the current behaviour (with my improvements above) is the best we'll reaslitically get (at least until evaluate has some better support for current file contexts).

  18. modified the milestones: v3.80.0, v3.82.0 on Dec 21, 2023
  19. DanTup commented on Jan 22, 2024

    @DanTup
    Member

    dart-lang/sdk@793755f improved the error message and removed the verbose stack traces.

    We can't disable the input box when there's no active file (as noted above), but it should be clear now when this fails because you're not paused and have no active Dart file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in debuggingRelates to the debug adapter or process of running debug sessionsis bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions