Describe the bug
If an error/exception is thrown within onTransition, the bloc stops working completely:
bloc.add stops adding events or mapEventToState doesn't receive them.
To Reproduce
@override
void onTransition(transition) {
throw new Exception('Explooooosion');
}
The bloc remains broken even if you comment out the exception, and hot reload.
The reason seems to stem from:
transformStates(transformEvents(_eventSubject, (Event event) {
currentEvent = event;
return mapEventToState(currentEvent).handleError(_handleError);
})).forEach(
(State nextState) {
if (state == nextState || _stateSubject.isClosed) return;
final transition = Transition(
currentState: state,
event: currentEvent,
nextState: nextState,
);
BlocSupervisor.delegate.onTransition(this, transition);
onTransition(transition); // <-- Will cause processing to stop.
_stateSubject.add(nextState);
},
);
.forEach states:
If this stream emits an error, or if the call to [action] throws, the returned future completes with that error, and processing stops.
The workaround for now is simply to try catch code running in onTransition.
Hi @larssn 馃憢
Thanks for opening an issue!
Good point, I'll have this fixed asap 馃憤
Fixed in #643 and included in bloc v1.0.1 馃帀
Most helpful comment
Fixed in #643 and included in
bloc v1.0.1馃帀