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: spawn actor on logger be alive after throwing an js error #5088

Open
betterRunner opened this issue Sep 20, 2024 · 0 comments
Open

Bug: spawn actor on logger be alive after throwing an js error #5088

betterRunner opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@betterRunner
Copy link

XState version

XState version 5

Description

Hi there, I made an experiment to test if a child spawn actor can restore nornal status after throwing an error, here is the process:

  1. A parent actor creates a spawn actor:
      childrenActorRef: ({ self, spawn }) => ({
        [ChildStateMachine.CHILD1]: spawn(createChild1Machine()),
      }),
    }),
  1. And I manually throw an error in child1:
   [SOME_EVENT]: {
      // this will throw an js error
      const a = undefined;
      console.log(a.b);
  }
}
  1. And I can successfully subscribe the error by following the official doc
    error: (err) => {
         // can catch the error here
         console.error(err);

         // but this event will no longer be received by the child1 actor
        child1Actor.send({ type: 'SOME_EVNET2' })
    }
})
  1. But the strange thing is the child1 actor seems has crashed and no longer be able to receive any events.

I don't know if it is a reasonable behavior as I haven't found related description in official docs about the behavior of an actor after throwing js error. But my understanding is: since I catch the error, the actor should still be working.

Expected result

Expected the child1 actor can still be alive and able to receive events normally even after throwing an js error

Actual result

the child1 actor seems has crashed and no longer be able to receive any events.

Reproduction

https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vanilla-ts

Additional context

No response

@betterRunner betterRunner changed the title Bug: spawn actor on logger live after throwing an js error Bug: spawned actor on logger be alive after throwing an js error Sep 20, 2024
@betterRunner betterRunner changed the title Bug: spawned actor on logger be alive after throwing an js error Bug: spawn actor on logger be alive after throwing an js error Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant