Skip to content

Commit 01f31db

Browse files
committed
Handle changes with new logger
This catches some previously uncaught crash reports that were missed because of the change in pattern in the new logger.
1 parent 3ba0606 commit 01f31db

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

.travis.yml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
sudo: false
2-
31
language: elixir
4-
52
elixir:
63
- 1.11.1
7-
- 1.8.0
84
otp_release:
9-
- 23.1.0
10-
- 20.0.0
5+
- 23.1
116

12-
stages:
13-
- check formatted
14-
- test
15-
16-
jobs:
7+
matrix:
178
include:
18-
- stage: test
19-
script: mix test
9+
- elixir: 1.11.1
10+
otp_release: 23.1
11+
- elixir: 1.8.0
12+
otp_release: 19.3
2013

21-
- stage: check formatted
22-
script: mix format --check-formatted
14+
script:
15+
- if [[ "$TRAVIS_ELIXIR_VERSION" == "1.11"* ]]; then mix format --check-formatted; fi
16+
- mix test
17+
sudo: false
18+
dist: trusty
19+
cache:
20+
directories:
21+
- _build
22+
- deps

lib/rollbax/reporter/standard.ex

+41-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ defmodule Rollbax.Reporter.Standard do
1010
handle_error_format(format, data)
1111
end
1212

13-
def handle_event(_type, _event) do
13+
def handle_event(:error_report, {_, :crash_report, data}) do
14+
handle_error_format(:crash_report, data)
15+
end
16+
17+
def handle_event(_, _) do
1418
:next
1519
end
1620

@@ -70,6 +74,41 @@ defmodule Rollbax.Reporter.Standard do
7074
}
7175
end
7276

77+
defp handle_error_format(:crash_report, [data, _]) do
78+
{m, f, a} = Keyword.fetch!(data, :initial_call)
79+
80+
name =
81+
case Keyword.get(data, :registered_name) do
82+
[] -> data |> Keyword.fetch!(:pid) |> inspect()
83+
name -> inspect(name)
84+
end
85+
86+
{class, message, stacktrace} =
87+
case Keyword.fetch!(data, :error_info) do
88+
{_, %class{message: message}, stacktrace} ->
89+
{inspect(class), message, stacktrace}
90+
91+
{_, info, stacktrace} when is_tuple(info) ->
92+
case elem(info, 0) do
93+
%class{message: message} -> {inspect(class), message, stacktrace}
94+
{%class{message: message}, inner_stacktrace} -> {inspect(class), message, inner_stacktrace}
95+
reason -> {"Unknown", inspect(reason, limit: :infinity), stacktrace}
96+
end
97+
end
98+
99+
%Rollbax.Exception{
100+
class: "Task terminating (#{class})",
101+
message: message,
102+
stacktrace: stacktrace,
103+
custom: %{
104+
name: name,
105+
started_from: data |> Keyword.fetch!(:ancestors) |> hd() |> inspect(),
106+
function: inspect(Function.capture(m, f, length(a))),
107+
arguments: inspect(a)
108+
}
109+
}
110+
end
111+
73112
defp handle_error_format('** State machine ' ++ _ = message, data) do
74113
if charlist_contains?(message, 'Callback mode') do
75114
:next
@@ -94,7 +133,7 @@ defmodule Rollbax.Reporter.Standard do
94133

95134
# Any other error (for example, the ones logged through
96135
# :error_logger.error_msg/1). This reporter doesn't report those to Rollbar.
97-
defp handle_error_format(_format, _data) do
136+
defp handle_error_format(_, _) do
98137
:next
99138
end
100139

mix.lock

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
%{
2-
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "f4763bbe08233eceed6f24bc4fcc8d71c17cfeafa6439157c57349aa1bb4f17c"},
3-
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm", "db622da03aa039e6366ab953e31186cc8190d32905e33788a1acb22744e6abd2"},
4-
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm", "1b34655872366414f69dd987cb121c049f76984b6ac69f52fff6d8fd64d29cfd"},
5-
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm", "f050061c87ad39478c942995b5a20c40f2c0bc06525404613b8b0474cb8bd796"},
6-
"hackney": {:hex, :hackney, "1.3.2", "43bd07ab88753f5e136e38fddd2a09124bee25733b03361eeb459d0173fc17ab", [:make, :rebar], [{:idna, "~> 1.0.2", [hex: :idna, repo: "hexpm", optional: false]}, {:ssl_verify_hostname, "~> 1.0.5", [hex: :ssl_verify_hostname, repo: "hexpm", optional: false]}], "hexpm", "9b811cff637b29f9c7e2c61abf01986c85cd4f64a9422315fd803993b4e82615"},
7-
"idna": {:hex, :idna, "1.0.3", "d456a8761cad91c97e9788c27002eb3b773adaf5c893275fc35ba4e3434bbd9b", [:rebar3], [], "hexpm", "357d489a51112db4f216034406834f9172b3c0ff5a12f83fb28b25ca271541d1"},
8-
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b96c400e04b7b765c0854c05a4966323e90c0d11fee0483b1567cda079abb205"},
9-
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], [], "hexpm", "8aad5eef6d9d20899918868b10e79fc2dafe72a79102882c2947999c10b30cd9"},
10-
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm", "c1c408c57a1e4c88c365b9aff1198c350e22b765dbb97a460e9e6bd9364c6194"},
11-
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm", "6e56493a862433fccc3aca3025c946d6720d8eedf6e3e6fb911952a7071c357f"},
12-
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.6", "45866d958d9ae51cfe8fef0050ab8054d25cba23ace43b88046092aa2c714645", [:make], [], "hexpm", "72b2fc8a8e23d77eed4441137fefa491bbf4a6dc52e9c0045f3f8e92e66243b5"},
2+
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
3+
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
4+
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
5+
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
6+
"hackney": {:hex, :hackney, "1.3.2", "43bd07ab88753f5e136e38fddd2a09124bee25733b03361eeb459d0173fc17ab", [:make, :rebar], [{:idna, "~> 1.0.2", [hex: :idna, repo: "hexpm", optional: false]}, {:ssl_verify_hostname, "~> 1.0.5", [hex: :ssl_verify_hostname, repo: "hexpm", optional: false]}], "hexpm"},
7+
"idna": {:hex, :idna, "1.0.3", "d456a8761cad91c97e9788c27002eb3b773adaf5c893275fc35ba4e3434bbd9b", [:rebar3], [], "hexpm"},
8+
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
9+
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], [], "hexpm"},
10+
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
11+
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
12+
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.6", "45866d958d9ae51cfe8fef0050ab8054d25cba23ace43b88046092aa2c714645", [:make], [], "hexpm"},
1313
}

test/rollbax/logger_test.exs

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule Rollbax.LoggerTest do
3333
def init(args), do: {:ok, args}
3434

3535
def handle_cast(:raise_elixir, state) do
36-
Map.fetch!(%{}, :nonexistent_key)
36+
_ = Map.fetch!(%{}, :nonexistent_key)
3737
{:noreply, state}
3838
end
3939
end
@@ -47,11 +47,11 @@ defmodule Rollbax.LoggerTest do
4747
data = assert_performed_request()["data"]
4848

4949
# Check the exception.
50-
assert data["body"]["trace"]["exception"] == %{
50+
assert %{
5151
"class" => "GenServer terminating (KeyError)",
52-
"message" => "key :nonexistent_key not found in: %{}"
53-
}
54-
52+
"message" => message
53+
} = data["body"]["trace"]["exception"]
54+
assert message =~ "key :nonexistent_key not found"
5555
assert [frame] = find_frames_for_current_file(data["body"]["trace"]["frames"])
5656
assert frame["method"] == "MyGenServer.handle_cast/2"
5757

@@ -247,7 +247,7 @@ defmodule Rollbax.LoggerTest do
247247
~r[anonymous fn/0 in Rollbax.LoggerTest.(\")?test task with anonymous function raising an error(\")?/1]
248248

249249
assert data["custom"]["name"] == inspect(task)
250-
assert data["custom"]["function"] =~ ~r/\A#Function<.* in Rollbax\.LoggerTest/
250+
assert data["custom"]["function"] =~ ~r/Rollbax\.LoggerTest/
251251
assert data["custom"]["arguments"] == "[]"
252252
end)
253253
end
@@ -270,10 +270,9 @@ defmodule Rollbax.LoggerTest do
270270
assert [frame] = find_frames_for_current_file(data["body"]["trace"]["frames"])
271271
assert frame["method"] == "MyModule.raise_error/1"
272272

273-
assert data["custom"] == %{
273+
assert Map.take(data["custom"], ["name", "function", "started_from"]) == %{
274274
"name" => inspect(task),
275275
"function" => "&MyModule.raise_error/1",
276-
"arguments" => ~s(["my message"]),
277276
"started_from" => inspect(self())
278277
}
279278
end)

0 commit comments

Comments
 (0)