Skip to content

sink.add() throws when using typed message #2401

Closed

Description

@hadjiprocopis

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

Activity

  1. lrhn commented on May 13, 2026

    @lrhn
    Member

    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.

  2. added
    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
    type-documentationA request to add or improve documentation
    on May 18, 2026
  3. added a commit that references this issue on Aug 6, 2026
    7760774
  4. added a commit that references this issue on Aug 8, 2026
    56cc50c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package:stream_channeltype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)type-documentationA request to add or improve documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions