Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly reports common :gen_server abnormal exits #18

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tower_honeybadger/honeybadger/notice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule TowerHoneybadger.Honeybadger.Notice do
stacktrace: stacktrace,
plug_conn: plug_conn
}) do
error_notice("(exit)", reason, stacktrace, plug_conn)
error_notice("(exit)", Exception.format_exit(reason), stacktrace, plug_conn)
end

defp error_notice(class, message, stacktrace, plug_conn) do
Expand Down
47 changes: 46 additions & 1 deletion test/tower_honeybadger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

capture_log(fn ->
in_unlinked_process(fn ->
1 / 0

Check warning on line 68 in test/tower_honeybadger_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.14, plug_1_14)

the call to //2 will fail with ArithmeticError

Check warning on line 68 in test/tower_honeybadger_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.14, plug_1_14)

the call to //2 will fail with ArithmeticError

Check warning on line 68 in test/tower_honeybadger_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.14, plug_1_14)

the call to //2 will fail with ArithmeticError
end)
end)
end)
Expand Down Expand Up @@ -126,7 +126,7 @@
%{
"error" => %{
"class" => "(exit)",
"message" => "abnormal",
"message" => ":abnormal",
"backtrace" => backtrace_entries
},
"server" => %{
Expand Down Expand Up @@ -159,6 +159,51 @@
end)
end

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

assert(
{
:ok,
%{
"error" => %{
"class" => "(exit)",
"message" => "bad return value: \"bad value\"",
"backtrace" => backtrace_entries
},
"server" => %{
"environment_name" => "test"
}
}
} = Jason.decode(body)
)

assert(
%{
"file" => "test/tower_honeybadger_test.exs",
"method" =>
~s(anonymous fn/0 in TowerHoneybadgerTest."test reports :gen_server bad exit"/1),
"number" => 201
} = List.first(backtrace_entries)
)

done.()

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

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

defp waiting_for(fun) do
# ref message synchronization trick copied from
# https://github.com/PSPDFKit-labs/bypass/issues/112
Expand Down