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

Bug: throwing an error within onReceive in invoked callback service isn't being caught by onError #3279

Closed
koenoe opened this issue May 9, 2022 · 5 comments

Comments

@koenoe
Copy link

koenoe commented May 9, 2022

Description

When throwing an error within onReceive in an invoked callback service, it's not caught. Thrown errors outside onReceive are caught properly. Therefore I'm forced to do something like callback({ type: 'ERROR', error }) in order to handle the error properly and transition to an error state in my state machine.

Expected result

I expect the error to be caught, so my callback service fails and I can transition to an error state properly.

Actual result

Error is not caught and state machine ends up in an invalid state.

Reproduction

https://codesandbox.io/s/pensive-curran-6p4vvx?file=/src/index.js

Additional context

Checked with @mattpocock on Stately Discord and seems to be a bug.

@koenoe koenoe added the bug label May 9, 2022
@Andarist
Copy link
Member

Andarist commented May 9, 2022

This is somewhat related to: statelyai/rfcs#4 . We are planning to have strong guarantees about errors in v5.

@Andarist Andarist added this to the 5.0 milestone May 9, 2022
@mattpocock
Copy link
Contributor

This feels like its own thing - surely any error thrown inside an invoked callback should result in the onError transition being taken?

@Andarist
Copy link
Member

Andarist commented May 9, 2022

It should but it also doesn't 😅 There are just a lot of errors that are currently swallowed in XState, for instance, onError won't usually be taken in the parent machine when a child machine errors somewhere (like in assign or whatever).

So while we could improve things in v4 bit by bit - I feel like it's better to focus on the algorithm overhaul and ship this improvement in v5. Merging v4 to v5 already has a non-trivial cost and any changes to the core logic like this have the potential of being problematic in this sense.

@mattpocock
Copy link
Contributor

OK, boss 👍

@Andarist
Copy link
Member

I believe that #4145 & #4492 addressed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants