You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debug Console doesn't add clickable links for stdout output when using new Flutter SDK debug adapters #4711
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:
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
Current Pre Release
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
Reacted by Saropa Developer, 7bit0-0, Greg Sullivan, Alex S, Adrian Vintu, Pedro Gomes, Raşit Ayaz, Per Lycke, Artur Saidov, Raghav Joshi and 4 more
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 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.
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.
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
We don't perform stack trace parsing on stdout output (only known errors)
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).
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.
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.
@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.
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).
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?
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).
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
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.
Sorry for the delay/inconvenience!
Reacted by Shahid Bangash, Lars, Martin Sellergren and arshak
Reacted by creativecreatorormaybenot and Agon Noga
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.
Activity
DanTup commentedon Aug 31, 2023
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.
Tanthus commentedon Aug 31, 2023
That is great to hear. Thank you. I never thought to try "Structured Errors" in my searches.
DanTup commentedon Sep 1, 2023
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!
Tanthus commentedon Sep 5, 2023
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
Add a Log.note('something') anywhere and you will get the source where that came from.
DanTup commentedon Sep 5, 2023
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:
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.
[-]Missing code links in "Debug Output" window[/-][+]Debug Console doesn't add clickable links for stdout output when using new SDK debug adapters[/+]DanTup commentedon Sep 5, 2023
Turns out there are two issues here:
package:stack_traceto 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).Tanthus commentedon Sep 5, 2023
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.
saropa commentedon Sep 18, 2023
Hi, we are facing this issue too. Could you explain the trick? I was unable to figure it out from reading above!
DanTup commentedon Sep 25, 2023
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 remaining items
martinsellergren commentedon Mar 19, 2024
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.
adrianvintu commentedon Mar 19, 2024
How can we transform a
print(s)to stderr, or whatever is required to be interpreted as a stack?DanTup commentedon Mar 19, 2024
For a Dart application, you could use
stderr.write/stderr.writelnto 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).adrianvintu commentedon Mar 19, 2024
No solution for Flutter (android and ios)? Some workaround?
This is how we catch errors:
larssn commentedon Mar 26, 2024
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": truedoes nothing apparently.DanTup commentedon Mar 26, 2024
@adrianvintu
I don't have any good workaround (besides using legacy adapters, but that's not great), but if you only need
Sentryfor release builds, I wonder if you could skip settingFlutterError.onErrorfor debug builds so the normal Flutter handling occurs?@larssn
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
useLegacyDebugAdaptersis 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).
[-]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[/+]DanTup commentedon May 13, 2024
This is now fixed in the latest Flutter master. Output to
stdoutis scanned for stack frames in the same way asstderrand the white links will appear on the right side.Sorry for the delay/inconvenience!
larssn commentedon May 14, 2024
Outstanding!
adrianvintu commentedon Oct 10, 2024
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.
DanTup commentedon Oct 10, 2024
@adrianvintu please file a new issue with some code to reproduce the issue you're seeing and a screenshot of what you see. Thanks!