Skip to content

Commit f97ab26

Browse files
author
José Valim
committed
Keep original stacktrace on inspect errors
Signed-off-by: José Valim <[email protected]>
1 parent d969d42 commit f97ab26

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/elixir/lib/inspect/algebra.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ defmodule Inspect.Algebra do
185185
Inspect.inspect(map, opts)
186186
rescue
187187
e ->
188+
stacktrace = System.stacktrace
189+
188190
# Because we try to raise a nice error message in case
189191
# we can't inspect a struct, there is a chance the error
190192
# message itself relies on the struct being printed, so
@@ -198,9 +200,10 @@ defmodule Inspect.Algebra do
198200
Process.put(:inspect_trap, true)
199201
res = Inspect.Map.inspect(map, opts)
200202
formatted = IO.iodata_to_binary(format(res, :infinity))
201-
raise ArgumentError,
203+
reraise ArgumentError,
202204
"Got #{inspect e.__struct__} with message " <>
203-
"\"#{Exception.message(e)}\" while inspecting #{formatted}"
205+
"\"#{Exception.message(e)}\" while inspecting #{formatted}",
206+
stacktrace
204207
after
205208
Process.delete(:inspect_trap)
206209
end

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ defmodule Inspect.MapTest do
299299
assert_raise ArgumentError, msg, fn ->
300300
inspect(%Failing{})
301301
end
302+
303+
assert [{Inspect.Inspect.MapTest.Failing, :inspect, 2, _}|_] = System.stacktrace
302304
end
303305

304306
test :exception do

0 commit comments

Comments
 (0)