Skip to content

"Unable to find the library" for global evaluation when the current file is inside the lib folder #4932

Closed

Description

@techvx

Describe the bug
Any attempt to execute an expression in VS Code's debug console for a Flutter app running in debug mode prints back:

1 + 1
Unable to find the library for file:///e%3A/Development/_code/Flutter/app_5/lib/main.dart
#0      DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:1060:7)
<asynchronous suspension>
#1      BaseDebugAdapter.handle (package:dds/src/dap/base_debug_adapter.dart:141:7)
<asynchronous suspension>

To Reproduce
Steps to reproduce the behavior:

  1. Create a new app via "Flutter: New Project".
  2. Build it for Windows, in my case.
  3. Attempt to evaluate any expression in VSC's debug console.
  4. Observe the unable to find the library aforementioned error from above.

Expected behavior
Prior to the most recent upgrade to Flutter 3+ and Dart SDK 3.2.3, it was perfectly possible not only to evaluate arbitrary operations in global context, but also to reference the declarations in the main.dart directly. This was extremely useful for custom debugging, which would allow for inspection of surgical precision within any runtime object that required additional monitoring, as needed.

It would be most useful to get such an option back. Running the DevTools (2.28.4) directly in the browser, furthermore, still allows to do just that - at any point in time, with or without the breakpoint. DevTools aren't nearly as versatile and free of friction as the standard built-in debug console within VSC, however. Having to go back and forth in and out of the IDE adds quite a bit of additional mental overhead as well, which doesn't exactly feel as absolutely necessary.

I see that the #4636 issue was closed as completed. Can this be considered a regression? The #4899 appears to have similar working, though the context seems to be limited to Dart only, with no mentioning of Flutter. The exact error appears to be different too, here.

Screenshots

compare the debug console:

image

to the DevTools console:

image

Diagnostics

Workspace Environment
Dart Code extension: 3.80.0
Flutter extension: 3.80.0 (activated)

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

Workspace type: Flutter (LSP)

Dart (3.2.3): E:\Development\Flutter\3.3.10\bin\cache\dart-sdk
Flutter (3.16.6): E:\Development\Flutter\3.3.10 (Windows (windows-x64/windows))

Output from `dart info`

E:\Development\Flutter\3.3.10\bin\cache\dart-sdk\bin\dart.exe 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.2.3 (stable) (Tue Dec 5 17:58:33 2023 +0000) on "windows_x64"
  • on windows / "Windows 10 Pro" 10.0 (Build 19045)
  • locale is en-US

Project info

  • sdk constraint: '>=3.2.3 <4.0.0'
  • dependencies: flutter
  • dev_dependencies: flutter_lints, flutter_test
  • elided dependencies: 2

Process info

Memory CPU Elapsed time Command line
82 MB -- dart.exe
14 MB -- dart.exe
39 MB -- dart.exe
456 MB -- dart.exe
47 MB -- dart.exe
41 MB -- dart.exe
86 MB -- dart.exe
126 MB -- dart.exe
374 MB -- dart.exe
85 MB -- dart.exe
Output from `flutter doctor`

E:\Development\Flutter\3.3.10\bin\flutter.bat doctor -v

[√] Flutter (Channel stable, 3.16.6, on Microsoft Windows [Version 10.0.19045.3930], locale en-US)
    • Flutter version 3.16.6 on channel stable at E:\Development\Flutter\3.3.10
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 46787ee49c (2 days ago), 2024-01-09 14:36:07 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at E:\Programs\AndroidSDK
    • Platform android-33, build-tools 30.0.3
    • Java binary at: E:\Programs\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.21)
    • Visual Studio at E:\Development\VS\Community
    • Visual Studio Community 2019 version 16.11.33027.164
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.2)
    • Android Studio at E:\Programs\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
    • android-studio-dir = E:\Programs\Android Studio
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.3930]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 120.0.6099.217
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 120.0.2210.121

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

• No issues found!

Activity

  1. added this to the v3.82.0 milestone on Jan 15, 2024
  2. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Jan 15, 2024
  3. changed the title [-]"Unable to find the library" in global evaluation context, no breakpoint[/-] [+]"Unable to find the library" for global evaluation context on Windows[/+] on Jan 15, 2024
  4. changed the title [-]"Unable to find the library" for global evaluation context on Windows[/-] [+]"Unable to find the library" for global evaluation context on Windows for Flutter apps[/+] on Jan 15, 2024
  5. DanTup commented on Jan 15, 2024

    @DanTup
    Member

    I can repro.. seems to be specific to Windows and Flutter. On macOS, Dart+Flutter work and on Windows, Dart works.

    For Windows + Flutter I get:

    Unable to find the library for file:///c%3A/Dev/Test%20Projects/dartcode_4932/lib/main.dart
    

    It seems unrelated to the casing of the drive letter (a common cause of errors like this) or the encoded colon (sending C:/ does not fix anything).

  6. DanTup commented on Jan 15, 2024

    @DanTup
    Member

    Here's the code where we try to locate the library:

    https://github.com/dart-lang/sdk/blob/ff1c32a52f1f1fd218b4e67db82697382ccddd13/pkg/dds/lib/src/dap/isolate_manager.dart#L1357

    We get all scripts from the VM and try to find the ones that match some version of the incoming URI. The computed candidate URIs in this case are:

    • file:///c%3A/Dev/Test%20Projects/dartcode_4932/lib/main.dart
    • file:///C:/Dev/Test%20Projects/dartcode_4932/lib/main.dart
    • file:///c:/Dev/Test%20Projects/dartcode_4932/lib/main.dart

    However the only main.dart in the result of running getScripts() is:

    ScriptRef id: libraries/@18093576/scripts/package%3Adartcode_4932%2Fmain.dart/18d0d0315c9, uri: package:dartcode_4932/main.dart
    

    This has a package: URI and not a file URI, so we don't match.

    Two thoughts:

    1. resolvePathToUri did not correctly turn the file:/// URI into a package: URI
    2. the getScripts() call returns different things compared to macOS

    Edit:

    The difference between Dart and Flutter was actually not a difference between Dart and Flutter, it was because in Dart I was testing in the bin folder (which doesn't have a package URI).

    In that case, we do see a script with a file: URI:

    script [
      Script id: libraries/@18315408/scripts/file%3A%2F%2F%2FC%3A%2FDev%2FTest%2520Projects%2Fdartcode_4932_dart%2Fbin%2Fdartcode_4932_dart.dart/18d0d107972,
      uri: file:///C:/Dev/Test%20Projects/dartcode_4932_dart/bin/dartcode_4932_dart.dart,
      library: [
        LibraryRef id: libraries/@18315408,
        name: ,
        uri: file:///C:/Dev/Test%20Projects/dartcode_4932_dart/bin/dartcode_4932_dart.dart
      ]
    ]
    

    But trying a lib file in Dart also fails:

    Unable to find the library for file:///c%3A/Dev/Test%20Projects/dartcode_4932_dart/lib/dartcode_4932_dart.dart
    

    Edit2: Turns out, it fails on macOS for Dart lib folder too:

    Unable to find the library for file:///Users/danny/Desktop/dart_samples/dartcode_4932_dart/lib/dartcode_4932_dart.dart
    

    Similar to Windows, we have this candidate URI:

    • file:///Users/danny/Desktop/dart_samples/dartcode_4932_dart/lib/dartcode_4932_dart.dart

    But in scripts, we only have the package: URI:

    • ScriptRef id: libraries/@19169571/scripts/package%3Adartcode_4932_dart%2Fdartcode_4932_dart.dart/18d0d253e77, uri: package:dartcode_4932_dart/dartcode_4932_dart.dart]

    Which raises the question... Why does it work for Flutter on MacOS? 🤔

    Turns out it does not. It's not clear what I tested previously, but now on latest master I'm seeing the same issue:

    1+1
    Unable to find the library for file:///Users/danny/Desktop/dart_samples/dartcode_4932/lib/main.dart
    
  7. changed the title [-]"Unable to find the library" for global evaluation context on Windows for Flutter apps[/-] [+]"Unable to find the library" for global evaluation when the current file is inside the lib folder[/+] on Jan 15, 2024
  8. DanTup commented on Jan 15, 2024

    @DanTup
    Member

    Working on a fix at https://dart-review.googlesource.com/c/sdk/+/346400. Unfortunately it's not possible to work around the issue in the VS Code extension so the fix is going to come via a future SDK release.

  9. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Jan 15, 2024
  10. DanTup commented on Jan 24, 2024

    @DanTup
    Member

    Fixed by dart-lang/sdk@a95b584. Ships in a future SDK release (rather than a Dart-Code release).

  11. dotkaio commented on May 25, 2024

    @dotkaio

    the error persists

  12. DanTup commented on May 28, 2024

    @DanTup
    Member

    @dotkaio if you're on the latest version of the Dart/Flutter SDK and also the latest version of VS Code + Dart extension, could you file a new issue about this and include a log file from reproducing this in a sample project?

    • Use the Dart: New Project or Flutter: New Project commands to create a new project
    • Run the Dart: Capture Debugging Logs command to start capturing logs
    • Reproduce the issue
    • Click Cancel on the logging notification to stop logging and open the log file
    • Open a new issue with the log file (ensuring it contains nothing sensitive - which should only be file paths if you did it using a new sample project)

    Thanks!

  13. iulian0512 commented on Aug 19, 2024

    @iulian0512

    @DanTup is global evaluation supposed to work when attached to an android device(flutter app) ?

  14. DanTup commented on Aug 19, 2024

    @DanTup
    Member

    @iulian0512 if you have a Dart file open, yep. If it doesn't work for you, please file a new issue with steps to reproduce and a screenshot of what you see. Thanks!

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