Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reactor/executor/step_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ defmodule Reactor.Executor.StepRunner do
|> handle_run_result(reactor, step, arguments, context)
rescue
reason ->
error = RunStepError.exception(step: step, error: reason)
error = RunStepError.exception(step: step, error: reason, stacktrace: __STACKTRACE__)
Hooks.event(reactor, {:run_error, error}, step, context)

maybe_compensate(reactor, step, error, arguments, context)
Expand Down
2 changes: 0 additions & 2 deletions lib/reactor/step/anon_fn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ defmodule Reactor.Step.AnonFn do
{m, f, a} when is_atom(m) and is_atom(f) and is_list(a) ->
apply(m, f, [arguments, context] ++ a)
end
rescue
error -> {:error, error}
end

@doc false
Expand Down
7 changes: 0 additions & 7 deletions test/reactor/step/anon_fn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ defmodule Reactor.Step.AnonFnTest do
test "it can handle an MFA" do
assert :marty = run(%{first_name: :marty}, %{}, run: {__MODULE__, :example, []})
end

test "it rescues errors" do
fun = fn _, _ -> raise "Marty" end

assert {:error, error} = run(%{}, %{}, run: fun)
assert Exception.message(error) =~ "Marty"
end
end

def example(arguments, _context) do
Expand Down
48 changes: 48 additions & 0 deletions test/reactor/step/error_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule Reactor.Step.ErrorTest do
@moduledoc false
use ExUnit.Case, async: true

defmodule ErrorStep do
@moduledoc false
use Reactor.Step

@impl true
def run(_argument, _context, _options) do
raise "This step always returns an error"
end
end

defmodule ErrorReactor do
@moduledoc false
use Reactor

step :named_step, ErrorStep
end

defmodule AnonErrorReactor do
@moduledoc false
use Reactor

step :step do
run fn _, _ ->
raise "This always returns an error"
end
end
end

test "it has stacktrace available in error" do
{:error, %{errors: [%{stacktrace: stacktrace}]}} = Reactor.run(ErrorReactor, %{})
[{ErrorStep, :run, 3, opts} | _] = stacktrace.stacktrace

assert Keyword.get(opts, :line) == 11
assert Keyword.get(opts, :file) == ~c"test/reactor/step/error_test.exs"
end

test "it has stacktrace available when running anonymous step" do
{:error, %{errors: [%{stacktrace: stacktrace}]}} = Reactor.run(AnonErrorReactor, %{})
[{AnonErrorReactor, _anon_fn_name, _arity, opts} | _] = stacktrace.stacktrace

assert Keyword.get(opts, :line) == 28
assert Keyword.get(opts, :file) == ~c"test/reactor/step/error_test.exs"
end
end