V5: error handling for actions #4505
-
|
I am not sure if this need to be reported as a bug, but I am having issues with how to handle unhandled errors in actions (works well with actor logic like I am expecting 2 things from the following scenario:
1. is satisfied in my local tests, but not 2. (status is const machine = createMachine({
initial: 'pending',
states: {
pending: {
entry: () => {
throw new Error('unhandled_sync_error_on_state_entry');
}
}
}
});
const actorRef = createActor(machine);
actorRef.subscribe({
error: (error) => {
// the error 'unhandled_sync_error_on_state_entry' sync error is caught here
}
});
actorRef.start();
// actorRef.getSnapshot().status is errorI tried to add this test in the error test suite as I think this should be the expected behavior, but it fails (just note that I am new to it(`unhandled sync errors thrown on state entry should crash the parent`, (done) => {
const machine = createMachine({
initial: 'pending',
states: {
pending: {
entry: () => {
throw new Error('unhandled_sync_error_on_state_entry');
}
}
}
});
const actorRef = createActor(machine);
actorRef.subscribe({
error: (error) => {
expect((error as Error).message).toBe('unhandled_sync_error_on_state_entry');
// error is caught here, we throw for upstream (global)
throw new Error('unhandled_sync_error_on_state_entry_global');
}
});
actorRef.start();
expect(actorRef.getSnapshot().status).toBe('error');
installGlobalOnErrorHandler((ev) => {
ev.preventDefault();
expect(ev.error.message).toEqual('unhandled_sync_error_on_state_entry_global');
done();
});
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I think that this open PR resolves both of your concerns: #4492 . Could you recheck your expectations with its content? |
Beta Was this translation helpful? Give feedback.
I think that this open PR resolves both of your concerns: #4492 . Could you recheck your expectations with its content?