diff --git a/lib/actors/actor/caller_consumer.ex b/lib/actors/actor/caller_consumer.ex index d3b28b15..ce4dc8e7 100644 --- a/lib/actors/actor/caller_consumer.ex +++ b/lib/actors/actor/caller_consumer.ex @@ -618,23 +618,28 @@ defmodule Actors.Actor.CallerConsumer do end end) rescue - e -> - Logger.error( - "Failure to make a call to actor #{inspect(actor.id.name)} #{inspect(e)}" - ) - - reraise e, __STACKTRACE__ + err -> + Logger.error(Exception.format(:error, err, __STACKTRACE__)) + + {:error, :actor_invoke, err} + catch + :exit, err -> + # no need to log because this is already logged by the system + {:error, :actor_invoke, err} end |> case do - result = :error -> - {:cont, result} - - result = {:error, msg} -> + :error = result -> {:cont, result} - result = {:error, :action_not_found, msg} -> + {:error, :action_not_found, _msg} = result -> {:halt, result} + {:error, :actor_invoke, error} -> + {:halt, {:error, error}} + + {:error, _msg} = result -> + {:cont, result} + result -> {:halt, result} end diff --git a/spawn_sdk/spawn_sdk/test/actor/actor_test.exs b/spawn_sdk/spawn_sdk/test/actor/actor_test.exs index dff4d94f..fa3fbe53 100644 --- a/spawn_sdk/spawn_sdk/test/actor/actor_test.exs +++ b/spawn_sdk/spawn_sdk/test/actor/actor_test.exs @@ -40,6 +40,13 @@ defmodule Actor.ActorTest do |> Value.void() end) + action("test_error", fn _ctx, _payload -> + # match error + 1 = 2 + + Value.of() + end) + action("sum", fn %Context{} = ctx, %MyMessageRequest{id: id, data: data} -> current_state = ctx.state new_state = current_state @@ -408,6 +415,19 @@ defmodule Actor.ActorTest do end describe "invoke with routing" do + test "simple exception error inside an action", ctx do + system = ctx.system + + dynamic_actor_name = "#{inspect(make_ref())}" <> "simple_error" + + assert {:error, _response} = + SpawnSdk.invoke(dynamic_actor_name, + ref: "my_actor_ref", + system: system, + action: "test_error" + ) + end + test "simple call that goes through 3 actors piping each other", ctx do system = ctx.system