nact icon indicating copy to clipboard operation
nact copied to clipboard

Stateless Actors won't handle errors

Open juanstiza opened this issue 1 year ago • 1 comments

Stateless actors are unable to catch errors being thrown in the main function. I assume this should be the case, but please let me know if it is not. I will fall-back to using regular actors.

Expected Behavior

An error being thrown inside a Stateless actor's function should:

  1. Be caught
  2. Be handled by onCrash and escalated properly

Current Behavior

Error doesn't get thrown and actor get's stuck

Possible Solution

No clue

Steps to Reproduce (for bugs)

import nact from "nact";
const system = nact.start();
const delay = (time) => new Promise((res) => setTimeout(res, time));

const ping = nact.spawnStateless(
  system,
  async (msg, ctx) => {
    console.log(msg);
    await delay(500);

    throw new Error("oh no!");
  },
  "ping",
  {
    onCrash: (msg, e, ctx) => {
      console.log(e)
      return ctx.escalate
    }
  }
);

nact.dispatch(ping, {
  hello: "World!"
});

This outputs:

{ hello: 'World!' }

Context

I'm trying to use stateless actors to perform simple tasks, but I need these to respond to errors

Your Environment

Tested in node v14.21.3 and v18.14.2 on MacOS 13.4.1

juanstiza avatar Jul 06 '23 13:07 juanstiza

@juanstiza I'd recommend that you take a look at https://www.npmjs.com/package/@nact/core, as this should I believe fix this problem.

ncthbrt avatar Jul 10 '23 09:07 ncthbrt