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

Issue with async*, error handling and ddc #35624

Open
NevRA opened this Issue Jan 10, 2019 · 6 comments

Comments

Projects
None yet
4 participants
@NevRA
Copy link

NevRA commented Jan 10, 2019

I have a code:

Future<int> doJobFuture(int i) async {
  throw 'error';
}

Stream<int> doJob(Stream<int> input) async* {
  await for (final i in input) {
    try {
      final res = await doJobFuture(i);
      yield res;
    } catch (e) {
      print(e);
    }
  }
}

void main() async {
  final sc = new StreamController<int>.broadcast(sync: false);
  doJob(sc.stream).listen((t) => print(t));

  await Future.delayed(const Duration(seconds: 1), () {
    sc.add(1);
    sc.add(1);
    sc.add(1);
  });
}

It works fine on VM and I can see 3 errors messages in console (from catch block).
If I run this example on ddc I'll get only 1 error with 1 actual attempt to execute doJobFuture method.

Looks like something wrong with exceptions handling from Future inside 'await for' block.

If I change final res = await doJobFuture(i); to the throw Exception('error'); I'll get expected result.
If I change try - catch block to the Future methods (then, cathcError) it works fine too.

Dart VM version: 2.1.0 (Tue Nov 13 18:22:02 2018 +0100) on "macos_x64"
Chrome
MacOS

@lrhn

This comment has been minimized.

Copy link
Member

lrhn commented Jan 15, 2019

If I run this in dartpad (adding an import of dart:async), it prints three "error"s, so it may depend on the version in use.

@natebosch

This comment has been minimized.

Copy link
Member

natebosch commented Jan 15, 2019

I'm only able to reproduce with DDC, not with dart2js

@NevRA

This comment has been minimized.

Copy link

NevRA commented Jan 15, 2019

@lrhn yes, dartpad uses VM that is why it works fine.
@natebosch strange, I'll double check it.

@natebosch

This comment has been minimized.

Copy link
Member

natebosch commented Jan 15, 2019

@lrhn yes, dartpad uses VM that is why it works fine.

dartpad uses dart2js, but the version may lag a bit behind what is in the SDK.

@NevRA

This comment has been minimized.

Copy link

NevRA commented Jan 15, 2019

Yeah, you are right guys. I checked and issue related ONLY to the DDC. Dev experience still may be affected but no issues on prod. Sorry for the confusion.
I replaced dart2js with ddc in description
Thanks!

@NevRA NevRA changed the title Issue with async*, error handling and dart2js Issue with async*, error handling and ddc Jan 15, 2019

@NevRA

This comment has been minimized.

Copy link

NevRA commented Jan 15, 2019

Can you set proper label?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment