#2827·a2ui

[BUG] [genui] A2uiTransportAdapter._pipelineSubscription missing onError (parser errors escape to uncaught-error zone)

Author: JunglianaCreated Sep 28, 2026Updated Sep 30, 2026
Labelstype: bugP1status: first-line-handledcomponent: genui

Internal issue: b/546034214

  • I have searched the existing issues to make sure this bug has not already been reported.

Describe the Bug

A2uiTransportAdapter._pipelineSubscription in packages/genui/lib/src/transport/a2ui_transport_adapter.dart subscribes to the internal _pipeline broadcast stream without providing an onError handler:

dart
void addChunk(String text) {
  _pipelineSubscription ??= _pipeline.listen((event) {
    if (event is A2uiMessageEvent) {
      _messageStream.add(event.message);
    }
  });
  _inputStream.add(text);
}

In Dart, broadcast streams deliver errors to each listener independently. When a broadcast stream listener does not provide an onError callback, any stream error triggers Zone.handleUncaughtError in that listener's captured zone.

As a result:

  1. When A2uiParserTransformer encounters an invalid or malformed chunk and emits an error via _controller.addError(...), that error escapes as an uncaught exception rather than being delivered to incomingMessages.
  2. Downstream callers who subscribe to Transport.incomingMessages with onError: (e) => ... never have their error handler invoked for parser errors.
  3. Applications must wrap every call to addChunk(...) in a runZonedGuarded block to prevent uncaught error crashes/log bursts.

Steps to Reproduce

Run the following unit test:

dart
import 'package:flutter_test/flutter_test.dart';
import 'package:genui/genui.dart';

void main() {
  test('parser errors flow to incomingMessages.onError', () async {
    final adapter = A2uiTransportAdapter();
    Object? capturedError;
    adapter.incomingMessages.listen(
      (_) {},
      onError: (Object e) => capturedError = e,
    );

    // Malformed JSON/A2UI payload that causes A2uiParserTransformer to emit an error
    adapter.addChunk('{"createSurface":{"surfaceId":"s","catalogId":"x"}}');
    await Future<void>.delayed(Duration.zero);

    expect(capturedError, isNotNull);
  });
}

Result: Test fails because capturedError is null, and an unhandled zone exception is logged.

Expected Behavior

Parser errors emitted during stream transformation should be forwarded to _messageStream.addError so subscribers to incomingMessages can observe and handle them.

dart
void addChunk(String text) {
  _pipelineSubscription ??= _pipeline.listen(
    (event) {
      if (event is A2uiMessageEvent) {
        _messageStream.add(event.message);
      }
    },
    onError: _messageStream.addError,
  );
  _inputStream.add(text);
}

Environment Details

  • SDK/Package Name & Version: package:genui 0.10.x (packages/genui/lib/src/transport/a2ui_transport_adapter.dart)
  • Protocol Version: v0.9 / v0.9.1