Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0ea80c

Browse files
authored
fix: Add stacktrace to exception (#265)
* fix: Add stacktrace to exceptionWhen an exception occured inside of a Reactor.Step it would not show the stacktrace but only the error message.This change includes the stacktrace in the exception and also adds a test that validates this* fix: remove rescue statement inside AnonFn.run/3This prevented the stacktrace from being passed down to the executor.---------Co-authored-by: Rutger <rutgerdj@users.noreply.github.com>
1 parentc72cf38 commita0ea80c

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

‎lib/reactor/executor/step_runner.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ defmodule Reactor.Executor.StepRunner do
161161
|>handle_run_result(reactor,step,arguments,context)
162162
rescue
163163
reason->
164-
error=RunStepError.exception(step:step,error:reason)
164+
error=RunStepError.exception(step:step,error:reason,stacktrace:__STACKTRACE__)
165165
Hooks.event(reactor,{:run_error,error},step,context)
166166

167167
maybe_compensate(reactor,step,error,arguments,context)

‎lib/reactor/step/anon_fn.ex‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ defmodule Reactor.Step.AnonFn do
2929
{m,f,a}whenis_atom(m)andis_atom(f)andis_list(a)->
3030
apply(m,f,[arguments,context]++a)
3131
end
32-
rescue
33-
error->{:error,error}
3432
end
3533

3634
@docfalse

‎test/reactor/step/anon_fn_test.exs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ defmodule Reactor.Step.AnonFnTest do
1919
test"it can handle an MFA"do
2020
assert:marty=run(%{first_name::marty},%{},run:{__MODULE__,:example,[]})
2121
end
22-
23-
test"it rescues errors"do
24-
fun=fn_,_->raise"Marty"end
25-
26-
assert{:error,error}=run(%{},%{},run:fun)
27-
assertException.message(error)=~"Marty"
28-
end
2922
end
3023

3124
defexample(arguments,_context)do

‎test/reactor/step/error_test.exs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
defmoduleReactor.Step.ErrorTestdo
2+
@moduledocfalse
3+
useExUnit.Case,async:true
4+
5+
defmoduleErrorStepdo
6+
@moduledocfalse
7+
useReactor.Step
8+
9+
@impltrue
10+
defrun(_argument,_context,_options)do
11+
raise"This step always returns an error"
12+
end
13+
end
14+
15+
defmoduleErrorReactordo
16+
@moduledocfalse
17+
useReactor
18+
19+
step:named_step,ErrorStep
20+
end
21+
22+
defmoduleAnonErrorReactordo
23+
@moduledocfalse
24+
useReactor
25+
26+
step:stepdo
27+
runfn_,_->
28+
raise"This always returns an error"
29+
end
30+
end
31+
end
32+
33+
test"it has stacktrace available in error"do
34+
{:error,%{errors:[%{stacktrace:stacktrace}]}}=Reactor.run(ErrorReactor,%{})
35+
[{ErrorStep,:run,3,opts}|_]=stacktrace.stacktrace
36+
37+
assertKeyword.get(opts,:line)==11
38+
assertKeyword.get(opts,:file)==~c"test/reactor/step/error_test.exs"
39+
end
40+
41+
test"it has stacktrace available when running anonymous step"do
42+
{:error,%{errors:[%{stacktrace:stacktrace}]}}=Reactor.run(AnonErrorReactor,%{})
43+
[{AnonErrorReactor,_anon_fn_name,_arity,opts}|_]=stacktrace.stacktrace
44+
45+
assertKeyword.get(opts,:line)==28
46+
assertKeyword.get(opts,:file)==~c"test/reactor/step/error_test.exs"
47+
end
48+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp