Skip to content

Commit b5ca925

Browse files
committed
error inside invoke action
1 parent 4589fd1 commit b5ca925

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

lib/actors/actor/caller_consumer.ex

+16-11
Original file line numberDiff line numberDiff line change
@@ -618,23 +618,28 @@ defmodule Actors.Actor.CallerConsumer do
618618
end
619619
end)
620620
rescue
621-
e ->
622-
Logger.error(
623-
"Failure to make a call to actor #{inspect(actor.id.name)} #{inspect(e)}"
624-
)
625-
626-
reraise e, __STACKTRACE__
621+
error ->
622+
Logger.error(Exception.format(:error, error, __STACKTRACE__))
623+
624+
{:error, :actor_invoke, error}
625+
catch
626+
:exit, error ->
627+
# no need to log because this is already logged by the system
628+
{:error, :actor_invoke, error}
627629
end
628630
|> case do
629-
result = :error ->
630-
{:cont, result}
631-
632-
result = {:error, msg} ->
631+
:error = result ->
633632
{:cont, result}
634633

635-
result = {:error, :action_not_found, msg} ->
634+
{:error, :action_not_found, _msg} = result ->
636635
{:halt, result}
637636

637+
{:error, :actor_invoke, error} ->
638+
{:halt, {:error, error}}
639+
640+
{:error, _msg} = result ->
641+
{:cont, result}
642+
638643
result ->
639644
{:halt, result}
640645
end

spawn_sdk/spawn_sdk/test/actor/actor_test.exs

+22
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ defmodule Actor.ActorTest do
4040
|> Value.void()
4141
end)
4242

43+
action("test_error", fn _ctx, _payload ->
44+
# match error
45+
1 = 2
46+
47+
Value.of()
48+
end)
49+
4350
action("sum", fn %Context{} = ctx, %MyMessageRequest{id: id, data: data} ->
4451
current_state = ctx.state
4552
new_state = current_state
@@ -408,6 +415,21 @@ defmodule Actor.ActorTest do
408415
end
409416

410417
describe "invoke with routing" do
418+
test "simple match error inside an action", ctx do
419+
system = ctx.system
420+
421+
dynamic_actor_name = "#{inspect(make_ref())}" <> "simple_error"
422+
423+
assert {:ok, response} =
424+
SpawnSdk.invoke(dynamic_actor_name,
425+
ref: "my_actor_ref",
426+
system: system,
427+
action: "test_error"
428+
)
429+
430+
assert {:error, _} = response
431+
end
432+
411433
test "simple call that goes through 3 actors piping each other", ctx do
412434
system = ctx.system
413435

0 commit comments

Comments
 (0)