Skip to content

Commit cb5bfbc

Browse files
author
José Valim
committed
Ensure inspected strings are padded in function clause blaming
1 parent 695915b commit cb5bfbc

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/elixir/lib/exception.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,9 @@ defmodule FunctionClauseError do
975975
formatted_args =
976976
args
977977
|> Enum.with_index(1)
978-
|> Enum.map(fn {arg, i} -> "\n # #{i}\n #{inspect_fun.(arg)}\n" end)
978+
|> Enum.map(fn {arg, i} ->
979+
["\n # ", Integer.to_string(i), "\n ", pad(inspect_fun.(arg)), "\n"]
980+
end)
979981

980982
formatted_clauses =
981983
if clauses do
@@ -989,14 +991,21 @@ defmodule FunctionClauseError do
989991
|> Enum.take(10)
990992
|> Enum.map(format_clause_fun)
991993

992-
"\nAttempted function clauses (showing #{length(top_10)} out of #{length(clauses)}):" <>
993-
"\n\n#{top_10}"
994+
[
995+
"\nAttempted function clauses (showing #{length(top_10)} out of #{length(clauses)}):",
996+
"\n\n",
997+
top_10
998+
]
994999
else
9951000
""
9961001
end
9971002

9981003
"\n\nThe following arguments were given to #{mfa}:\n#{formatted_args}#{formatted_clauses}"
9991004
end
1005+
1006+
defp pad(string) do
1007+
String.replace(string, "\n", "\n ")
1008+
end
10001009
end
10011010

10021011
defmodule Code.LoadError do

0 commit comments

Comments
 (0)