Skip to content

Debug Console doesn't add clickable links for stdout output when using new Flutter SDK debug adapters #4711

Closed

Description

@Tanthus

Describe the bug
Until about a week ago in the PREVIEW release, clickable code links were showing up on the right side of the "Debug Output" window if the format was using this format:
<Regular output> (<package>:<file path>:<line number>:<column number>)
It was convenient.

Now the code appears unformatted and unclickable. I checked to see if there might have been a setting that got turned off but couldn't find anything to enable that feature.

Note the release version of the plugin still works as described

To Reproduce
Steps to reproduce the behavior:

  1. Print to the console with say: print('New route pushed: ServicesRoute (package:app/router.dart:61:9)'

Expected behavior
The above line should produce a clickable link on the right side

Screenshots
Release version
Release version of extension

Current Pre Release
Pre Release of extension

Please complete the following information:

  • Operating System and version: Windows 10
  • VS Code version: 1.81.1
  • Dart extension version: v3.71.20230831 pre release
  • Dart/Flutter SDK version: 3.1.0 (stable)
  • Target device (if the issue relates to Flutter debugging): Android

Activity

  1. DanTup commented on Aug 31, 2023

    @DanTup
    Member

    I think you're seeing #4571 which was fixed via flutter/flutter#131251 but was unfortunately after the cut for the last stable release.

    The fix should be in the Flutter beta branch and in the next stable release.

  2. Tanthus commented on Aug 31, 2023

    @Tanthus
    Author

    That is great to hear. Thank you. I never thought to try "Structured Errors" in my searches.

  3. DanTup commented on Sep 1, 2023

    @DanTup
    Member

    Apparently I didn't look at your screenshots closely enough - I just noticed that the output here is not actually part of structured errors, so I'm less certain if the fix above will handle this. The change does add stack trace parsing to structured errors, but I'm not sure if it occurs for general output.

    I'll keep this open and do some testing. Thanks!

  4. added this to the v3.74.0 milestone on Sep 1, 2023
  5. added
    in flutterRelates to running Flutter apps
    in debuggingRelates to the debug adapter or process of running debug sessions
    on Sep 1, 2023
  6. Tanthus commented on Sep 5, 2023

    @Tanthus
    Author

    I noticed that the Code output issues I described above started to appear today. I noticed that the Dart Plugin updated from 3.70.0 to 3.72.1. Updated flutter (stable 3.13.1), tried the beta channel of flutter too (beta 3.14.0-0.1.pre), no change. I then downgraded the Dart plugin back to 3.70.0, which the source code now showed up on the side again. Just for compleatness I tried the Dart Plugin version 3.72.0, and that didn't work as well as the pre-release version 3.73.20230905. Also tried a default "flutter create" project with some code, that had the same results.

    Anyway, my short-term fix is just to use 3.70.0

    Here is the code I used to get the source lines

    class Log {
    	static final Map<int,RegExp> _rxMap = {};
    
    	static String fromSource([int pos=2]) {
    		final m = (_rxMap[pos] ?? (_rxMap[pos] = RegExp(r'^\#' '$pos' r'[^\(]*\(([^\)]*)',multiLine: true))).firstMatch(StackTrace.current.toString(),);
    		return m == null ? '':m[1]!;
    	}
    
    	// Should compile out completely in release mode.
    	static void note(Object? obj) {
    		if (kDebugMode) {
    			print('$obj (${fromSource()})');
    		}
    	}
    }
    

    Add a Log.note('something') anywhere and you will get the source where that came from.

  7. DanTup commented on Sep 5, 2023

    @DanTup
    Member

    The reason you saw this in the pre-release and v3.72 and not in v3.70 is that in v3.72 (and the recent pre-releases) I increased the percentage of users that get the new SDK debug adapters. These are better in most ways, but have the issue described above.

    Switching to v3.70 works, but you can also switch back to the original debug adapters (in v3.72) by adding the following to your VS Code user settings JSON:

    // Force new debug adapters off
    // https://github.com/Dart-Code/Dart-Code/issues/4711
    "dart.previewSdkDaps": false,
    

    The latest versions of Flutter (master and perhaps beta) have the structured errors issue resolved. I need to do some more testing of your examples above to figure out whether there's still more (non-structured-errors) output that was previously handled but is not now though.

  8. changed the title [-]Missing code links in "Debug Output" window[/-] [+]Debug Console doesn't add clickable links for stdout output when using new SDK debug adapters[/+] on Sep 5, 2023
  9. DanTup commented on Sep 5, 2023

    @DanTup
    Member

    Turns out there are two issues here:

    1. We don't perform stack trace parsing on stdout output (only known errors)
    2. The new debug adapters use package:stack_trace to parse stack frames which doesn't parse bare strings in the format given above (whereas the legacy debug adapters did their own parsing and weren't fussy about the format)

    The second will need fixing in Dart/DDS and the first may be fixable in either Dart or Flutter depending on whether we want to scan all output (which means making all output asynchronous, since looking up package: URIs may involve a call to the VM).

  10. Tanthus commented on Sep 5, 2023

    @Tanthus
    Author

    I understand. I am doing the stdout formatting as a trick to get the links for my print statements (see code above) primarily for my debug sanity and since it worked.

  11. saropa commented on Sep 18, 2023

    @saropa

    stdout formatting as a trick

    Hi, we are facing this issue too. Could you explain the trick? I was unable to figure it out from reading above!

  12. DanTup commented on Sep 25, 2023

    @DanTup
    Member

    The "trick" doesn't work on the new SDK DAPs. Tanthus was printing stack traces so they were in the format that the old debug adapters detected as stack traces and would automatically link up. The new debug adapters are more strict and currently only scanning real errors for stack traces.

  13. removed this from the v3.74.0 milestone on Sep 26, 2023
  14. 13 remaining items

  15. martinsellergren commented on Mar 19, 2024

    @martinsellergren

    @martinsellergren real errors are when there is an exception that is unhandled (so is printed to stderr by Dart) or handled by Flutter (which triggers a "structured error").

    If you're printing the stack trace yourself (eg. the debugger doesn't specifically know it's a stack trace, it's just some string output that happens to contain a stack trace) then that's what this issue is covering.

    Got it, thanks for the explanation. I believe what I'm seeing is another issue then. I'll create a new issue shortly.

    edit: Seems, dart:developer's log() doesn't print stackTraces to stderr. So what I'm seeing is probably same issue.

  16. adrianvintu commented on Mar 19, 2024

    @adrianvintu

    How can we transform a print(s) to stderr, or whatever is required to be interpreted as a stack?

  17. DanTup commented on Mar 19, 2024

    @DanTup
    Member

    How can we transform a print(s) to stderr, or whatever is required to be interpreted as a stack?

    For a Dart application, you could use stderr.write/stderr.writeln to write directly to the stderr stream. Unfortunately this won't work for Flutter, because the way output streams works for Flutter is different (because the debugger doesn't run the application directly, it runs Flutter, which may run the application on another device).

  18. adrianvintu commented on Mar 19, 2024

    @adrianvintu

    No solution for Flutter (android and ios)? Some workaround?

    This is how we catch errors:

    FlutterError.onError =
        (FlutterErrorDetails errorDetails) => resolveExceptions(
              errorDetails.exception,
              errorDetails.stack,
            );
    
    ....
    
    void resolveExceptions(
      Object error,
      StackTrace? stack,
    ) {
      if (kDebugMode) {
        print(error);
        print(stack);
      }
    
      Sentry.captureException(error, stackTrace: stack);
    }
    
  19. larssn commented on Mar 26, 2024

    @larssn

    EDIT: It's working now. Maybe a restart of VSCode was needed after setting dart.useLegacyDebugAdapters? Not sure. Anything, thanks DanTup.

    We just migrated to the newest Flutter/Dart today, and are seeing the above, even with Flutter's default error handling.

    Not sure how to resolve it. "dart.useLegacyDebugAdapters": true does nothing apparently. 

  20. DanTup commented on Mar 26, 2024

    @DanTup
    Member

    @adrianvintu

    Some workaround? This is how we catch errors:

    I don't have any good workaround (besides using legacy adapters, but that's not great), but if you only need Sentry for release builds, I wonder if you could skip setting FlutterError.onError for debug builds so the normal Flutter handling occurs?

    @larssn

    Maybe a restart of VSCode was needed after setting dart.useLegacyDebugAdapters

    No restart of VS Code should be required, but you will need to start a new debug session (the setting is read during the debug session start).

    Note: Using useLegacyDebugAdapters is not a good long-term fix because the legacy adapters are not getting new features as the language evolves.

    I do hope to look at this soon, but it needs some refactoring across both Dart + Flutter debug adapters (and because of how the Dart adapter rolls into Flutter, this isn't as straightforward as I'd like).

  21. changed the title [-]Debug Console doesn't add clickable links for stdout output when using new SDK debug adapters[/-] [+]Debug Console doesn't add clickable links for stdout output when using new Flutter SDK debug adapters[/+] on Apr 15, 2024
  22. DanTup commented on May 13, 2024

    @DanTup
    Member

    This is now fixed in the latest Flutter master. Output to stdout is scanned for stack frames in the same way as stderr and the white links will appear on the right side.

    image

    Sorry for the delay/inconvenience!

  23. modified the milestones: On Deck, v3.90.0 on May 13, 2024
  24. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on May 13, 2024
  25. larssn commented on May 14, 2024

    @larssn

    Outstanding!

  26. adrianvintu commented on Oct 10, 2024

    @adrianvintu

    Thank you @DanTup. I removed the Sentry and debugPrint stack. The stack is still not rendered as stack, but as text. There is no option to click on files in the debug view.

  27. DanTup commented on Oct 10, 2024

    @DanTup
    Member

    @adrianvintu please file a new issue with some code to reproduce the issue you're seeing 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 sessionsin flutterRelates to running Flutter appsis 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