xstate icon indicating copy to clipboard operation
xstate copied to clipboard

[core] Add support for handling communication errors

Open davidkpiano opened this issue 3 years ago • 3 comments
trafficstars

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).

davidkpiano avatar Dec 20 '21 18:12 davidkpiano

⚠️ 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

changeset-bot[bot] avatar Dec 20 '21 18:12 changeset-bot[bot]

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

ghost avatar Dec 20 '21 18:12 ghost

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
  }
}

huan avatar Dec 20 '21 18:12 huan

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.

Andarist avatar Sep 13 '23 11:09 Andarist