Skip to content

Unable to catch exceptions occurring within async* function returning a Stream in Web(Flutter for Web, DartPad). #140199

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

Closed
eaglesakura opened this issue Dec 15, 2023 · 7 comments
Labels
blocked Issue is blocked by another issue dependency: dart Dart team may need to help us found in release: 3.16 Found to occur in 3.16 found in release: 3.18 Found to occur in 3.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically r: duplicate Issue is closed as a duplicate of an existing issue team-web Owned by Web platform team

Comments

@eaglesakura
Copy link

eaglesakura commented Dec 15, 2023

Steps to reproduce

  1. Run sample code in DartPad
  2. Please delete import 'package:flutter/material.dart';
  3. Run sample code in DartPad

Expected results

Console Log

Before(sample code)

v: 0
v: 1
// Freeze...

After(delete import 'package:flutter/material.dart'; )

v: 0
v: 1
e: Exception: error
finish

Actual results

Executing the provided code in DartPad results in freezing instead of handling the thrown exception gracefully, unlike other non-web Dart environments, where the exception is appropriately logged.

Code sample

Code sample
import 'dart:async';
import 'package:flutter/material.dart'; // <- delete this Line.

Future main() async {
  Stream<int> step1() async* {
    yield 0;
    await Future.delayed(const Duration(milliseconds: 100));
    yield 1;
    throw Exception('error');
  }

  Stream<int> step2() async* {
    await for (final v in step1()) {
      yield v;
    }
  }

  try {
    await for (final v in step2()) {
      print('v: $v');
    }
  } catch (e) {
    print('e: $e');
  }
  print('finish');
}

Screenshots or Video

Screenshots / Video demonstration

Image 2023-12-15 15-59-38

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]
@dam-ease dam-ease added the in triage Presently being triaged by the triage team label Dec 15, 2023
@dam-ease
Copy link

Hi @eaglesakura.
Thanks for filing this.
I can reproduce this on dartPad but this doesn't reproduce using other IDEs e.g VSCode, can you confirm this on your end as well?
If this is specific to DartPad, then the appropriate place to file this might be the dart-pad repo here https://github.com/dart-lang/dart-pad/issues

@dam-ease dam-ease added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 15, 2023
@eaglesakura
Copy link
Author

eaglesakura commented Dec 15, 2023

Thanks, @dam-ease .
This issue occurs in Flutter for Web.

Sample(with UI)

import 'package:flutter/material.dart';

Future main() async {
  Stream<int> step1() async* {
    yield 0;
    await Future.delayed(const Duration(milliseconds: 100));
    yield 1;
    throw Exception('error');
  }

  Stream<int> step2() async* {
    await for (final v in step1()) {
      yield v;
    }
  }

  try {
    await for (final v in step2()) {
      debugPrint('v: $v');
    }
  } catch (e) {
    debugPrint('e: $e');
  }
  debugPrint('finish, start app!');
  runApp(
    MaterialApp(
      title: 'Sample',
      theme: ThemeData.light(),
      home: const Scaffold(
        body: Center(
          child: Text(
            'Hello, World!',
          ),
        ),
      ),
    ),
  );
}

Console Log

Run on Chrome(VSCode / Debug Build):

v: 0
v: 1
// Freeze...

Run On Android(VSCode / Debug Build)

I/flutter ( 5373): v: 0
I/flutter ( 5373): v: 1
I/flutter ( 5373): e: Exception: error
I/flutter ( 5373): finish, start app!

Flutter Doctor output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.0, on macOS 14.1.2 23B92 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3)
[✓] VS Code (version 1.85.1)
[✓] Connected device (4 available)
[✓] Network resources

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 15, 2023
@dam-ease
Copy link

dam-ease commented Dec 18, 2023

Thanks for your response.
I can reproduce this as well on the latest master and stable channels.

Deleting this line as in steps

import 'package:flutter/material.dart'; // <- delete this Line.

The issue still occurs on flutter web but doesn't with DartPad.

flutter doctor -v

[!] Flutter (Channel stable, 3.16.4, on macOS 14.0 23A344 darwin-arm64, locale
    en-NG)
    • Flutter version 3.16.4 on channel stable at
      /Users/damilolaalimi/sdks/flutter
    ! Warning: `dart` on your path resolves to
      /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/damilolaalimi/sdks/flutter.
      Consider adding /Users/damilolaalimi/sdks/flutter/bin to the front of your
      path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2e9cb0aa71 (6 days ago), 2023-12-11 14:35:13 -0700
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/damilolaalimi/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)

[!] Android Studio (version unknown)
    • Android Studio at /Users/damilolaalimi/Downloads/Android Studio
      Preview.app/Contents
    • 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
    ✗ Unable to determine Android Studio version.
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.85.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] VS Code (version 1.83.1)
    • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] Connected device (4 available)
    • Damilola’s iPhone (mobile) • 00008110-001964480AE1801E            • ios
      • iOS 17.1.1 21B91
    • iPhone 15 (mobile)         • F17D2919-6D61-4295-8408-1719692FE958 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)            • macos                                •
      darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)               • chrome                               •
      web-javascript • Google Chrome 120.0.6099.109

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

! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.18.0-11.0.pre.96, on macOS 14.0 23A344 darwin-arm64, locale en-NG)
    • Flutter version 3.18.0-11.0.pre.96 on channel master at /Users/damilolaalimi/fvm/versions/master
    ! Warning: `flutter` on your path resolves to /Users/damilolaalimi/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/damilolaalimi/fvm/versions/master. Consider adding /Users/damilolaalimi/fvm/versions/master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 32d42b63de (19 hours ago), 2023-12-17 07:39:25 -0500
    • Engine revision 626c93260f
    • Dart version 3.3.0 (build 3.3.0-238.0.dev)
    • DevTools version 2.31.0-dev.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/damilolaalimi/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    ! CocoaPods 1.12.1 out of date (1.13.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[!] Android Studio (version unknown)
    • Android Studio at /Users/damilolaalimi/Downloads/Android Studio Preview.app/Contents
    • 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
    ✗ Unable to determine Android Studio version.
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.85.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] VS Code (version 1.83.1)
    • VS Code at /Users/damilolaalimi/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] Connected device (4 available)
    • Damilola’s iPhone (mobile) • 00008110-001964480AE1801E            • ios            • iOS 17.1.1 21B91
    • iPhone 15 (mobile)         • F17D2919-6D61-4295-8408-1719692FE958 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 120.0.6099.109

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

! Doctor found issues in 3 categories.

@dam-ease dam-ease changed the title Unable to catch exceptions occurring within async* function returning a Stream in Web(Flutrer for Web, DartPad). Unable to catch exceptions occurring within async* function returning a Stream in Web(Flutter for Web, DartPad). Dec 18, 2023
@dam-ease dam-ease added dependency: dart Dart team may need to help us platform-web Web applications specifically has reproducible steps The issue has been confirmed reproducible and is ready to work on team-web Owned by Web platform team found in release: 3.16 Found to occur in 3.16 found in release: 3.18 Found to occur in 3.18 framework flutter/packages/flutter repository. See also f: labels. and removed in triage Presently being triaged by the triage team labels Dec 18, 2023
@mraleph
Copy link
Member

mraleph commented Dec 18, 2023

cc @nshahan DDC discrepancy?

@sigmundch
Copy link
Contributor

DDC discrepancy?

Correct! Makes sense based on the fact that dartpad with a flutter import uses DDC and without uses dart2js. I confirmed locally and filed dart-lang/sdk#54411 to track on our end.

@sigmundch sigmundch added the blocked Issue is blocked by another issue label Dec 19, 2023
@yjbanov
Copy link
Contributor

yjbanov commented Dec 21, 2023

Closing in favor of the Dart SDK issue.

@yjbanov yjbanov closed this as completed Dec 21, 2023
@dam-ease dam-ease added r: invalid Issue is closed as not valid r: duplicate Issue is closed as a duplicate of an existing issue and removed r: invalid Issue is closed as not valid labels Dec 22, 2023
Copy link

github-actions bot commented Jan 5, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked Issue is blocked by another issue dependency: dart Dart team may need to help us found in release: 3.16 Found to occur in 3.16 found in release: 3.18 Found to occur in 3.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically r: duplicate Issue is closed as a duplicate of an existing issue team-web Owned by Web platform team
Projects
None yet
Development

No branches or pull requests

5 participants