don't swallow stack traces - #64
Conversation
|
There's an inconsistency: only the exception path is changed to We can keep the stacktrace internal and reraise it only where the bug actually lives — the default exception_clause =
if Keyword.has_key?(clauses, :else) do
# user-supplied else: keep the historical contract (bare exception)
quote do
{:exception, e, _stacktrace} ->
case e do
unquote(else_clause)
end
end
else
# default: reraise with the original stacktrace instead of `raise e`
quote do
{:exception, e, stacktrace} ->
reraise e, stacktrace
end
endplus the one-line internal change in - {:cont, {:exception, e}}
+ {:cont, {:exception, e, __STACKTRACE__}}The Why it's better
The stacktrace test still passes unchanged: test "reraises with the original stacktrace when giving up on an exception" do
formatted =
try do
retry with: [1] do
boom()
end
rescue
e -> Exception.format(:error, e, __STACKTRACE__)
end
assert formatted =~ "(RuntimeError) boom"
assert formatted =~ "RetryTest.boom" # points at the failing site, not retry.ex
endThe one thing this PR gives that the non-breaking version doesn't: exposing the stacktrace to custom |
this is a breaking change, but it will allow exceptions to retain their original stack traces when a retry fails