[BUG] [genui] A2uiTransportAdapter._pipelineSubscription missing onError (parser errors escape to uncaught-error zone)
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:
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:
- When
A2uiParserTransformerencounters an invalid or malformed chunk and emits an error via_controller.addError(...), that error escapes as an uncaught exception rather than being delivered toincomingMessages. - Downstream callers who subscribe to
Transport.incomingMessageswithonError: (e) => ...never have their error handler invoked for parser errors. - Applications must wrap every call to
addChunk(...)in arunZonedGuardedblock to prevent uncaught error crashes/log bursts.
Steps to Reproduce
Run the following unit test:
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.
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:genui0.10.x (packages/genui/lib/src/transport/a2ui_transport_adapter.dart) - Protocol Version: v0.9 / v0.9.1
Source: a2ui-project/a2ui