Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error thrown within onTransition breaks the Bloc. #641

Closed
larssn opened this issue Nov 4, 2019 · 2 comments
Closed

Error thrown within onTransition breaks the Bloc. #641

larssn opened this issue Nov 4, 2019 · 2 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@larssn
Copy link

larssn commented Nov 4, 2019

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.

@felangel
Copy link
Owner

felangel commented Nov 4, 2019

Hi @larssn 👋
Thanks for opening an issue!

Good point, I'll have this fixed asap 👍

@felangel felangel self-assigned this Nov 4, 2019
@felangel felangel added the bug Something isn't working label Nov 4, 2019
@felangel felangel added this to To do in bloc Nov 4, 2019
@felangel felangel moved this from To do to Blocked in bloc Nov 4, 2019
@felangel felangel moved this from Blocked to In progress in bloc Nov 4, 2019
@felangel
Copy link
Owner

felangel commented Nov 4, 2019

Fixed in #643 and included in bloc v1.0.1 🎉

@felangel felangel closed this as completed Nov 4, 2019
@felangel felangel moved this from In progress to Done in bloc Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
bloc
  
Done
Development

No branches or pull requests

2 participants