Skip to content

Commit 2bafb17

Browse files
author
José Valim
committed
Print warning when inspect fails
1 parent cf84ed3 commit 2bafb17

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lib/elixir/lib/inspect/algebra.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ defmodule Inspect.Algebra do
110110
if elem(opts, Inspect.Opts.__record__(:index, :records)) do
111111
try do
112112
Inspect.inspect(arg, opts)
113-
catch
114-
_, _ -> Inspect.Tuple.inspect(arg, opts)
113+
rescue
114+
e ->
115+
res = Inspect.Tuple.inspect(arg, opts)
116+
IO.puts :stderr, "** (Inspect.Error) Got #{inspect e.__record__(:name)} with message " <>
117+
"#{e.message} while inspecting #{pretty(res, opts.width)}"
118+
res
115119
end
116120
else
117121
Inspect.Tuple.inspect(arg, opts)

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,20 @@ defmodule Inspect.TupleTest do
156156
assert inspect(RuntimeError.new) == "RuntimeError[message: \"runtime error\"]"
157157
end
158158

159-
defrecord :something, [:a, :b]
160-
161-
test :non_module_record do
162-
# They are on purpose not treated as Elixir records
163-
# otherwise it affects inspect performance very strongly
164-
assert inspect(:something.new) == "{:something, nil, nil}"
165-
end
166-
167159
defrecord Rec, value: 1
168160

169161
test :two_items_record do
170162
assert inspect({ Rec[value: 1], 1 }) == "{Inspect.TupleTest.Rec[value: 1], 1}"
171163
end
172164

165+
test :false_positives do
166+
import ExUnit.CaptureIO
167+
168+
assert capture_io(:stderr, fn ->
169+
assert inspect({ Range, nil }) == "{Range, nil}"
170+
end) =~ "** (Inspect.Error) Got FunctionClauseError with message no function clause matching in Inspect.Range.inspect/2"
171+
end
172+
173173
test :empty do
174174
assert inspect({}) == "{}"
175175
end

lib/elixir/test/elixir/range_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ defmodule RangeTest do
4545
test :inspect do
4646
assert inspect(1..3) == "1..3"
4747
assert inspect(3..1) == "3..1"
48-
assert inspect({ Range, nil }) == "{Range, nil}"
4948
end
5049

5150
defp not_range do

0 commit comments

Comments
 (0)