Repository navigation
Closed
Labels
package:stream_channeltype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)type-documentationA request to add or improve documentationA request to add or improve documentation
Description
I am following the example code in the API docs (https://github.com/dart-lang/tools/blob/main/pkgs/stream_channel/example/example.dart) of the latest version 2.1.4.
Specifically, I am creating a MultiChannel whose messages are of a specific type. But I get this:
Unhandled exception:
type 'List<Object?>' is not a subtype of type 'String' of 'data'
#0 _GuaranteeSink.add (package:stream_channel/src/guarantee_channel.dart:118:14)
#1 _MultiChannel.virtualChannel.<anonymous closure> (package:stream_channel/src/multi_channel.dart:212:35)
#2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
#3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#4 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#5 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#6 _StreamController._add (dart:async/stream_controller.dart:663:7)
#7 _StreamController.add (dart:async/stream_controller.dart:618:5)
#8 _RootZone.runUnaryGuarded (dart:async/zone.dart:1778:10)
#9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#11 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#12 _StreamController._add (dart:async/stream_controller.dart:663:7)
#13 _StreamController.add (dart:async/stream_controller.dart:618:5)
#14 _StreamSinkWrapper.add (dart:async/stream_controller.dart:898:13)
#15 _GuaranteeSink.add (package:stream_channel/src/guarantee_channel.dart:125:12)
#16 main (file:///xxx.dart)
#17 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:314:19)
#18 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)
This is a short version of the offending code:
import 'dart:async';
import 'package:stream_channel/stream_channel.dart';
void main() async {
var dummyCtrl1 = StreamChannelController<String>();
var multiChannel = MultiChannel<String>(dummyCtrl1.local);
var channel1 = multiChannel.virtualChannel();
channel1.sink.add("AAA");
}
What's more, the above does not bomb if the message type (<String>) is removed entirely or replaced by <dynamic>.
Note: a question regarding this issue was posted here: https://stackoverflow.com/questions/79939911/stream-channel-multichannel-virtualchannel-sink-addmsg-throws-when-using-typ
Metadata
Metadata
Assignees
Labels
package:stream_channeltype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)type-documentationA request to add or improve documentationA request to add or improve documentation
Activity
lrhn commentedon May 13, 2026
The documentation says that the inner channel "must take JSON-like objects", so you can't use a
<String>channel as inner channel,The example is wrong.
Fix MultiChannel inner channel type constraint documentation (#2491)
Fix MultiChannel inner channel type constraint documentation (dart-la…