-
Notifications
You must be signed in to change notification settings - Fork 1.7k
A catch block in an async*
method does not catch exceptions from await for
in DDC
#47764
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
cc @sigmundch for triage |
We are aware of issues where DDC's async implementation isn't correct. To help us prioritize the priority of fixing them can you give some context to how you discovered into this discrepancy? Was this triggered by a commonly use package or pattern from a framework? |
This came up when a google3 author hit the problem. I have only seen it come up in real code the one time and it does not relate to a common pattern. It's very confusing when it does come up. |
The issue is easily reproducible using the code in flutter/flutter#108866 |
please note that "DDC" == "Dart Dev Compiler" aka the Dart compiler used in debug mode for the web. also, for anyone interested, a work-around is to rewrite your code using try {
final response = /* get a stream */;
// works fine on every platform, including the web *except* on the web in the face of an exception in debug mode
await for (final chunk in response) {
final text = chunk.text;
if (text != null) yield text;
}
} on Exception catch(e) {
// won't get here on the web in debug mode until this issue is fixed
} can be rewritten like so: try {
final response = /* get a stream */;
// seems to work fine on every platform, exception or not, debug mode or not
yield* response
.map((chunk) => chunk.text)
.where((text) => text != null)
.cast<String>();
} on Exception catch(e) {
// handle the exception
} It's not as pretty as that |
@natebiggs Do you think we need to revisit the |
This is fixed with the new DDC async semantics. Those updates included changes for The updates to DDC's async semantics didn't make it into Dart 3.5 so they're not on the stable branch yet. They will be included with Dart 3.6 though. Changing DartPad to use the Beta channel instead of Stable also verifies that this will be fixed in 3.6. |
Using a
try/catch
around anawait for
behaves differently on DDC from other platforms. In DDC the catch block is never reached and the stream never completes.In the VM and dart2js this outputs:
In DDC this only outputs the first line.
The text was updated successfully, but these errors were encountered: