Skip to content
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

Debugger treats Streams that throw and have an error handler supplied through .listen() as uncaught #54788

Closed
jellynoone opened this issue Jan 31, 2024 · 6 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team

Comments

@jellynoone
Copy link

Consider the following example:

void main() async {
  _stream().listen(print, onError: print);
}

Stream<int> _stream() async* {
  for (var i = 0; i < 10; i++) {
    yield i;
  }

  throw Exception('Debugger always treats it as uncaught!');
}

Steps to reproduce:

  1. Run dart run --observe --pause-isolates-on-start streams.dart
  2. Open DevTools debugger
  3. Select Stop on uncaught exceptions
  4. Continue
  5. Observe the debugger stop at throw even though the error is handled via listen.

However, if we rewrite the example to:

void main() async {
  try {
    await for (var item in _stream()) {
      print(item);
    }
  } catch (e) {
    print(e);
  }
}

Stream<int> _stream() async* {
  for (var i = 0; i < 10; i++) {
    yield i;
  }

  throw Exception('Debugger always treats it as uncaught!');
}

The debugger does not pause. As expected...

If we yet again, however, rewrite the example to use .asBroadcastStream():

void main() async {
  try {
    await for (var item in _stream().asBroadcastStream()) {
      print(item);
    }
  } catch (e) {
    print(e);
  }
}

Stream<int> _stream() async* {
  for (var i = 0; i < 10; i++) {
    yield i;
  }

  throw Exception('Debugger always treats it as uncaught!');
}

There is a pause again on the throw.

Personally, I've encountered this issue when using some firebase packages, and
thinking I did some error handling wrong, only to figure out after some time,
that the errors were in fact handled, but the debugger reported them as not.

Dart version:
Dart SDK version: 3.2.6 (stable) (Wed Jan 24 13:41:58 2024 +0000) on "macos_arm64"

@devoncarew
Copy link
Member

This may be working as expected, but I'll let @bkonyi confirm.

@devoncarew devoncarew added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jan 31, 2024
@aam
Copy link
Contributor

aam commented Jan 31, 2024

@aam
Copy link
Contributor

aam commented Feb 1, 2024

perhaps

void AsyncAwareStackUnwinder::UnwindFrameToStreamListener() {
should have code similar to
awaiter_frame_.has_catch_error = true;

@mraleph
Copy link
Member

mraleph commented Feb 1, 2024

I have been sitting on a CL which should help here, but I have been delaying landing it because I have been slowly thinking through what we should even do with this? question.

CL is here: https://dart-review.googlesource.com/c/sdk/+/322720

@aam
Copy link
Contributor

aam commented Feb 1, 2024

what we should even do with this? question.

It might be that in this issue the problem is simpler and clearer: we don't recognize that particular stream listener has an exception handler.

@a-siva a-siva added triaged Issue has been triaged by sub team P2 A bug or feature request we're likely to work on labels Feb 1, 2024
@a-siva
Copy link
Contributor

a-siva commented Feb 1, 2024

what we should even do with this? question.

It might be that in this issue the problem is simpler and clearer: we don't recognize that particular stream listener has an exception handler.

Agree we should probably get the immediate issue fixed while @mraleph works on the CL listed above

@derekxu16 derekxu16 assigned mraleph and unassigned derekxu16 Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team
Projects
None yet
Development

No branches or pull requests

6 participants