From 2a5bf34c20aa6b4051b055fda0d6bab2ab562c06 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Apr 2017 15:51:39 +0200 Subject: [PATCH] Function clause errors use their nested stacktraces --- lib/appsignal/error_handler.ex | 9 +++++++-- test/appsignal/error_handler/error_matcher_test.exs | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/appsignal/error_handler.ex b/lib/appsignal/error_handler.ex index e31faf4cd..eaa440d77 100644 --- a/lib/appsignal/error_handler.ex +++ b/lib/appsignal/error_handler.ex @@ -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 diff --git a/test/appsignal/error_handler/error_matcher_test.exs b/test/appsignal/error_handler/error_matcher_test.exs index dcb4db427..4730d956a 100644 --- a/test/appsignal/error_handler/error_matcher_test.exs +++ b/test/appsignal/error_handler/error_matcher_test.exs @@ -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 @@ -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