Skip to content

Commit

Permalink
Function clause errors use their nested stacktraces
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkreeftmeijer committed Apr 25, 2017
1 parent 3f3815b commit 2a5bf34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/appsignal/error_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ defmodule Appsignal.ErrorHandler do
{:pid, pid},
{:registered_name, name},
{:error_info, {_kind, exception, stack}} | _], _linked]) do

msg = "Process #{crash_name(pid, name)} terminating"
stacktrace = extract_stacktrace(exception) || stack
{reason, message} = extract_reason_and_message(exception, msg)
{origin, reason, message, Backtrace.from_stacktrace(stack), nil}
{origin, reason, message, Backtrace.from_stacktrace(stacktrace), nil}
end

defp extract_stacktrace({_, stacktrace}) when is_list(stacktrace) do
stacktrace
end
defp extract_stacktrace(_), do: nil

@doc false
def format_stack(stacktrace) do
Expand Down
8 changes: 6 additions & 2 deletions test/appsignal/error_handler/error_matcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ defmodule Appsignal.ErrorHandler.ErrorMatcherTest do
|> reason(":function_clause")
|> message(~r(Process #PID<[\d.]+> terminating: {:function_clause...))
|> stacktrace([
"(stdlib) gen_server.erl:812: :gen_server.terminate/7",
"(elixir) unicode/unicode.ex:190: String.Unicode.length/1",
"test/appsignal/error_handler/error_matcher_test.exs:27: Appsignal.ErrorHandler.ErrorMatcherTest.CrashingGenServer.handle_info/2",
"(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4",
"(stdlib) gen_server.erl:667: :gen_server.handle_msg/5",
"(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3"
])
end
Expand All @@ -170,7 +173,8 @@ defmodule Appsignal.ErrorHandler.ErrorMatcherTest do
~r(Process #PID<[\d.]+> terminating: {:function_clause, \[{String.Uni...)
)
|> stacktrace([
"(elixir) lib/task/supervised.ex:116: Task.Supervised.exit/4",
"(elixir) unicode/unicode.ex:190: String.Unicode.length/1",
"(elixir) lib/task/supervised.ex:85: Task.Supervised.do_apply/2",
"(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3"
])
end
Expand Down

0 comments on commit 2a5bf34

Please sign in to comment.