xstate
xstate copied to clipboard
[core] Add support for handling communication errors
This PR adds support for handling communication errors when the targets of events sent between actors does not exist:
// ...
entry: sendParent('SOME_EVENT'), // pretend the parent does not exist...
on: {
'error.communication': {
actions: (_, e) => { console.log(e.message); } // this will happen instead of an error being thrown
}
}
If there is no 'error.communication' transition, then an error will be thrown (existing behavior).
⚠️ No Changeset found
Latest commit: 4fc6979706b0a10fc005296bfd03f102099ca421
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Can we have error.communication defined as an enum or literal string so that we can import and use it with static typed?
i.e.:
enum XStateTypes {
ErrorCommnication = 'error.communication'
}
import { XStateTypes } from 'xstate/types'
// ...
entry: sendParent('SOME_EVENT'), // pretend the parent does not exist...
on: {
[XStateTypes.ErrorCommunication]: {
actions: (_, e) => { console.log(e.message); } // this will happen instead of an error being thrown
}
}
Error handling might still require some work in v5 but I think that it will look different than what we have here so this PR can be closed for now.
