Skip to content

Commit 58c4efb

Browse files
committed
handle error
1 parent 68fef14 commit 58c4efb

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

lib/actors/actor/caller_consumer.ex

Lines changed: 16 additions & 11 deletions
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+
err ->
622+
Logger.error(Exception.format(:error, err, __STACKTRACE__))
623+
624+
{:error, :actor_invoke, err}
625+
catch
626+
:exit, err ->
627+
# no need to log because this is already logged by the system
628+
{:error, :actor_invoke, err}
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

Lines changed: 20 additions & 0 deletions
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,19 @@ defmodule Actor.ActorTest do
408415
end
409416

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

0 commit comments

Comments
 (0)