Skip to content

Commit

Permalink
fix: properly reports common :gen_server abnormal exits
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Oct 24, 2024
1 parent e1c2679 commit 325d5d9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tower_rollbar/rollbar/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule TowerRollbar.Rollbar.Item do
end

def from_event(%Tower.Event{kind: :exit, reason: reason, stacktrace: stacktrace} = event) do
trace("(exit)", reason, stacktrace, options_from_event(event))
trace("(exit)", Exception.format_exit(reason), stacktrace, options_from_event(event))
end

def from_event(%Tower.Event{kind: :message, level: level, reason: reason} = event) do
Expand Down
53 changes: 51 additions & 2 deletions test/tower_rollbar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule TowerRollbarTest do
"trace" => %{
"exception" => %{
"class" => "(exit)",
"message" => "abnormal"
"message" => ":abnormal"
},
"frames" => frames
}
Expand Down Expand Up @@ -159,6 +159,55 @@ defmodule TowerRollbarTest do
end)
end

test "reports :gen_server bad exit", %{bypass: bypass} do

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.17, 27.0, true)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.15, plug_1_15)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17, plug_1_14)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.17, 27.0, true)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.16, 26.2.5.4)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.15, plug_1_15)

test reports :gen_server bad exit (TowerRollbarTest)

Check failure on line 162 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17, plug_1_14)

test reports :gen_server bad exit (TowerRollbarTest)
waiting_for(fn done ->
Bypass.expect_once(bypass, "POST", "/item", fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)

assert(
%{
"data" => %{
"uuid" => _,
"environment" => "test",
"timestamp" => _,
"level" => "error",
"body" => %{
"trace" => %{
"exception" => %{
"class" => "(exit)",
"message" => "bad return value: \"bad value\""
},
"frames" => frames
}
}
}
} = Jason.decode!(body)
)

assert(
%{
"method" =>
~s(anonymous fn/0 in TowerRollbarTest."test reports :gen_server bad exit"/1),
"filename" => "test/tower_rollbar_test.exs",
"lineno" => 204
} = List.last(frames)
)

done.()

conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.resp(200, Jason.encode!(%{"ok" => true}))
end)

capture_log(fn ->
in_unlinked_process(fn ->
exit({:bad_return_value, "bad value"})
end)
end)
end)
end

test "error report includes request data when available via Plug.Cowboy", %{bypass: bypass} do
# An ephemeral port hopefully not being in the host running this code
plug_port = 51111
Expand Down Expand Up @@ -301,7 +350,7 @@ defmodule TowerRollbarTest do
"trace" => %{
"exception" => %{
"class" => "(exit)",
"message" => "abnormal"
"message" => ":abnormal"
},
# Plug.Cowboy doesn't provide stacktrace for exits
"frames" => []
Expand Down

0 comments on commit 325d5d9

Please sign in to comment.