Skip to content

Stacktrace can ignore user-owned file when using tearoff #56918

Closed as not planned
@FMorschel

Description

@FMorschel

Repro:

import 'dart:async';

void main() {
  var controller = StreamController<int>();
  var controller2 = StreamController<int>();
  controller2.stream.listen((v) => controller.add(v));
  controller2.add(42);
  controller.close();
  controller2.add(42);
}

This code throws an error:

Connecting to VM Service at ws://127.0.0.1:34837/-D1zY7tPPbM=/ws
Connected to the VM Service.
Unhandled exception:
Bad state: Cannot add event after closing
#0      _StreamController.add (dart:async/stream_controller.dart:605:24)
#1      main.<anonymous closure> (package:bug/bug.dart:6:47)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#4      _DelayedData.perform (dart:async/stream_impl.dart:542:14)
#5      _PendingEvents.handleNext (dart:async/stream_impl.dart:647:11)
#6      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:618:7)
#7      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#9      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#10     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

Exited (255).

Focus on line 1 (not 0) where it tells me the file, function, line and offset of where the error was thrown.

If you use a tear off:

import 'dart:async';

void main() {
  var controller = StreamController<int>();
  var controller2 = StreamController<int>();
  controller2.stream.listen(controller.add);
  controller2.add(42);
  controller.close();
  controller2.add(42);
}

This is the output:

Connecting to VM Service at ws://127.0.0.1:35306/udzDEf1Qq0U=/ws
Connected to the VM Service.
Unhandled exception:
Bad state: Cannot add event after closing
#0      _StreamController.add (dart:async/stream_controller.dart:605:24)
#1      _RootZone.runUnaryGuarded (dart:async/zone.dart:1609:10)
#2      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366:11)
#3      _DelayedData.perform (dart:async/stream_impl.dart:542:14)
#4      _PendingEvents.handleNext (dart:async/stream_impl.dart:647:11)
#5      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:618:7)
#6      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#7      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#8      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

Exited (255).

I have no more reference as to where this happened on my code. I think this should be better handled for better DX. I was struggling for more than half an hour on my Flutter project with many different files and pages when I realized where this could be happening. The uncaught exceptions also triggers inside the framework code and there is no way for you to go back to your own code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.closed-not-plannedClosed as we don't intend to take action on the reported issuetriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions