Skip to content

Commit 1d7d036

Browse files
committed
Make protocol errors pretty
A common complaint I here from people is that error messages in Elixir are not pretty. Generally, this seems to be only the case when there are large structs in codebases that render in one line and are hard to read. This PR changes the behavior to pretty inspect the structs in the case that a protocol is not implemented for some value. The downside here is that the logging will no longer be in one line, but I think this is a fair tradeoff for legibility
1 parent 50619b1 commit 1d7d036

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/elixir/lib/exception.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ defmodule Exception do
346346
defp rewrite_arg(arg) do
347347
Macro.prewalk(arg, fn
348348
{:%{}, meta, [__struct__: Range, first: first, last: last, step: step]} ->
349-
{:..//, meta, [first, last, step]}
349+
{:"..//", meta, [first, last, step]}
350350

351351
other ->
352352
other
@@ -1997,11 +1997,11 @@ defmodule Protocol.UndefinedError do
19971997

19981998
@impl true
19991999
def message(%{protocol: protocol, value: value, description: description}) do
2000-
"protocol #{inspect(protocol)} not implemented for #{inspect(value)} of type " <>
2000+
"protocol #{inspect(protocol)} not implemented for #{inspect(value, pretty: true)} of type " <>
20012001
value_type(value) <> maybe_description(description) <> maybe_available(protocol)
20022002
end
20032003

2004-
defp value_type(%{__struct__: struct}), do: "#{inspect(struct)} (a struct)"
2004+
defp value_type(%{__struct__: struct}), do: "#{inspect(struct, pretty: true)} (a struct)"
20052005
defp value_type(value) when is_atom(value), do: "Atom"
20062006
defp value_type(value) when is_bitstring(value), do: "BitString"
20072007
defp value_type(value) when is_float(value), do: "Float"

0 commit comments

Comments
 (0)