Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ final class StreamingDataSource implements DataSource {
_permanentShutdown = true;
_logger.error(
'Encountered an unrecoverable error: "$err", Shutting down.');
stop();
// The event must be added before calling stop, because stop closes
// the controller and adding an event after that throws a StateError.
_dataController.sink.add(StatusEvent(ErrorKind.unknown, null,
'Encountered unrecoverable error streaming'));
stop();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,28 @@ void main() {
});
});

group('stream error handling', () {
test(
'it emits a status event without throwing when the stream reports an '
'unrecoverable error', () async {
final controller = StreamController<Event>();
final (dataSource, _, statusManager) =
makeDataSourceForTest(controller.stream);

final statusChange = expectLater(
statusManager.changes,
emits(predicate<DataSourceStatus>((status) =>
status.lastError?.kind == ErrorKind.unknown &&
status.lastError?.message ==
'Encountered unrecoverable error streaming')));

dataSource.start();
controller.sink.addError(Exception('Unable to make request'));

await statusChange;
});
});

group('environment ID from the stream connection', () {
test('it uses the environment ID response header', () async {
final controller = StreamController<Event>();
Expand Down
Loading