-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Dart debugging in Visual Code throws handled exceptions as uncaught #37953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I know it's in poor taste to add a "me too" comment, but this seriously needs attention. I found my issue with flutter, but apparently it's not an isolated issue. I'm attempting to run the following: GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[
'email'
],
);
...
Future<FirebaseUser> _silentSignIn() async {
try {
_googleUser = await _googleSignIn.signInSilently(suppressErrors: false)
.catchError((e) {
print('$e');
});
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
idToken: googleAuth.idToken,
accessToken: googleAuth.accessToken
);
_firebaseUser = (await _auth.signInWithCredential(credential)).user;
print("signed in " + firebaseUser.displayName);
notifyListeners();
return firebaseUser;
} catch (error) {
print(error);
}
return null;
} Trying both ways to catch the error, and I still get the breakpoint as if it was unhandled. I'm at my wits end with this. |
Just to be sure - in the Debug side bar in VS Code, you only have "uncaught exceptions" ticked, and not "all exceptions"? (cc @zichangg) |
In my case, I have double checked that I have only uncaught exceptions ticked. |
@Kenji-K thanks! @zichangg I can repro this using a clean import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
void main() {
runApp(MyApp());
_silentSignIn();
}
GoogleSignIn _googleSignIn = GoogleSignIn(scopes: <String>['email']);
Future<void> _silentSignIn() async {
try {
await _googleSignIn.signInSilently(suppressErrors: false).catchError(print);
} catch (error) {
print(error);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(title: 'Demo', home: Text('test'));
}
} It repros in both VS Code and Android Studio (though in Android Studio the editor goes to the source of the exception, whereas VS Code walks up the stack to the first frame that's user code). The source of the exception is here: As I understood it, the VM should see the |
(I can't edit labels, but this might be |
From what I could gather, the dartlang team said that it is "impossible" for them to fix this, I am not an experienced dev and I don't need to be in order to know that that is not true, since other modern languages don't have this problem. |
I would agree that this is indeed an unpleasant usability issue for the debugger. I don't see any reason though why we would not be able to make this work in common situations given that we should be able to peek through future chains. In the code below: import 'dart:async';
Future<void> baz() async {
await null;
throw 'A';
}
Future<int> bar() => baz().then((value) => 10);
Future<int> foo() async {
try {
await bar();
} catch (e) {}
return 0;
}
void main(List<String> arguments) async {
await foo();
} Debugger stops at We also get a really weird truncated lazy async stack trace with no position information in the last frame (/cc @mkustermann @cskau-g): $ out/ReleaseX64/dart /tmp/uncaught.dart
#0 baz (file:///tmp/uncaught.dart:5:3)
<asynchronous suspension>
#1 bar.<anonymous closure> (file:///tmp/uncaught.dart)
<asynchronous suspension> |
Reason for truncation is probably usage of legacy Though generally speaking I think we should encourage users to use Also for certain cases it's not possible to select the right way to unwind, because a future can have multiple listeners, which would yield a back trace tree instead of a stack. We could possibly print an the tree, but that would bring in a whole lot of new issues (e.g. figure out nice way to print such a backtrace tree, making |
@mkustermann If I replace There is a consideration here that there is a lot of legacy code (written without async/await) and code written in mixed style - sometimes hidden inside SDK libraries and packages which user did not author. I think we should definitely make things work for |
Slightly related - this comes up quite a bit in the Dart-Code issue tracker, and I've generally been encouraging people to use return FutureBuilder<Widget>(
future: f,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return SuccessfulWidget();
} else if (snapshot.hasError) {
return ErrorMessageWidget(snapshot.error);
}
return LoadingSpinnerWidget();
}
); Here, the code that's handling the error is in |
There a bit of back-and-forth here, but we have no assignee and no clear action items, AFAICT. |
Regarding the truncated stack: We can investigate adding support for the legacy |
@cskau-g Could you investigate the uncaught error reporting functionality - both when it is actually caught (as this issue) as well as reporting exceptions as uncaught if the handler was specially marked (see flutter/flutter#17007) |
@cskau-g @mkustermann Any update? |
@cskau-g has landed changes on our side. The ball is now in Flutter court. |
@mraleph are the changes different to the ones in #17007? Although this sounds like the same issue, I believe it's actually the opposite problem. #17007 is about exceptions that Flutter is catching, but are logically uncaught (eg. expected behaviour is for the debugger to break). This issue is about exceptions that are being caught (eg. with |
My mistake, yeah it is a separate (mirror) issue. I got confused. |
mraleph and I agreed to push this off this milestone to avoid rushing the change in, seeing how it's already gotten reverted twice. The follow-up fix for the |
TEST=ASAN; Various 'causal' tests updated below. Issues addressed in this revision: - #44708 ASAN - #44700 SegFault Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-asan-linux-release-x64-try,analyzer-linux-release-try,analyzer-analysis-server-linux-try,analyzer-nnbd-linux-release-try Bug: #40815, #37953 Change-Id: I8b8f6ee2e5d4ca2e6bea988ec1cd9f912ddf8240 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180186 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
TEST=Added new Future.catchError pause-on-unhandled-exceptions test. Bug: #37953 Change-Id: Ieb3cf834eacad4f9b98ab2db0e5813e9bfa09747 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180840 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
With dfd5413 the last piece of the puzzle should now be in place. Closing this issue here. But as always, feel free to reopen if you encounter any further issues with the above cases. Thank you. |
@cskau-g seems to work great, thank you! |
hey sorry for a newbie question but do you have any idea when will flutter be built with this fix ? or how can I check it ? |
@DanTup I tried with Maybe last flutter |
@kevinmarrec |
When debugging this code on VS Code (F5) with only import 'package:http/http.dart' as http;
Future<void> main() async {
try {
await http.get(Uri.parse('www.fail.com'));
} catch (err) {
debugPrint('Error caught');
}
} VS Code still breaks (breakpoint) in third party ( Using import 'package:http/http.dart' as http;
Future<void> main() async {
http.get(Uri.parse('www.fail.com')).catchError((error) {
debugPrint('Error caught');
});
} $ dart --version
Dart SDK version: 2.13.0-30.0.dev (dev) (Fri Feb 12 04:33:47 2021 -0800) on "windows_x64" |
Yeah, I can see it does not work. It seems if you have more than one
|
@mraleph Good catch ! I can indeed confirm it breaks when there's more than one It will be my pleasure to test/try again when there's a fix coming up :) And it would be awesome if it got fixed before next Dart release lands :) |
I'll have a look. |
Sorry for asking an obvious question here. When can we get this fix included in dart sdk for fluttter? |
@namchuai I think we need to wait Dart 2.13 release and then most probably Flutter 2.1 will feature Dart 2.13 It may also be available on a beta Flutter channel in the coming weeks (may need to ask Flutter team to see if it can land quicker) |
@namchuai to expand on @kevinmarrec response. Dart's master branch is automatically continuously being rolled into Flutter's master branch. So if you are using master channel then you should already have a fix included (unfortunately at the moment that is the only channel of Flutter that includes the fix). All other branches are entirely aligned as well (e.g. beta channel of Flutter uses beta channel of Dart and the same for stable channel). Except for very serious bugs (e.g. crashes) there is no way to expedite this process - it happens at a fixed cadence. |
Still having this issue with 3rd party package (flutterchina/dio)
|
@a7md0 please file a new issue and provide a reproduction. just saying "Still having this issue" is unactionable for us, because we have fixed all cases we could reproduce - so your issue is likely something else. |
I think this a serious problem when working with dart/flutter.
flutter/flutter#33427
The text was updated successfully, but these errors were encountered: