Commit 5e3b4436f4c6ecfb785947e9138750a52cc25432

Thomas de Grivel 2022-02-03T12:22:50

stacktrace formatting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/lib/stack.ex b/lib/stack.ex
index a280d7c..f75604f 100644
--- a/lib/stack.ex
+++ b/lib/stack.ex
@@ -3,5 +3,15 @@ defmodule Stack do
   def to_string(stack), do: to_string(stack, [])
 
   def to_string([], acc), do: acc |> Enum.reverse() |> Enum.join("\n")
-  def to_string([elt | rest], acc), do: to_string(rest, [inspect(elt) | acc])
+  def to_string([{module, fun, arity, [file: file, line: line]} | rest], acc) do
+    str = "#{module}.#{fun}/#{arity} in #{file}:#{line}"
+    to_string(rest, [str | acc])
+  end
+  def to_string([{module, fun, arity, _} | rest], acc) do
+    str = "#{module}.#{fun}/#{arity}"
+    to_string(rest, [str | acc])
+  end
+  def to_string([elt | rest], acc) do
+    to_string(rest, [inspect(elt) | acc])
+  end
 end