Skip to content

Stateless Actors won't handle errors #142

@juanstiza

Description

@juanstiza

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions