Skip to content

Commit

Permalink
fix: support tuple value in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Oct 21, 2024
1 parent e3a9f2c commit 3db4f26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions lib/tower_rollbar/rollbar/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ defmodule TowerRollbar.Rollbar.Item do
end

def from_event(%Tower.Event{kind: :message, level: level, reason: reason} = event) do
message =
if is_binary(reason) do
reason
else
inspect(reason)
end

%{
"message" => %{
"body" => message
"body" => string_or_inspect(reason)
}
}
|> item_from_body(Keyword.merge([level: level], options_from_event(event)))
Expand All @@ -42,7 +35,7 @@ defmodule TowerRollbar.Rollbar.Item do
"frames" => frames(stacktrace),
"exception" => %{
"class" => class,
"message" => reason
"message" => string_or_inspect(reason)
}
}
}
Expand Down Expand Up @@ -177,4 +170,7 @@ defmodule TowerRollbar.Rollbar.Item do
defp os do
"type: #{inspect(:os.type())} version: #{inspect(:os.version())}"
end

defp string_or_inspect(data) when is_binary(data), do: data
defp string_or_inspect(data), do: inspect(data)
end
4 changes: 2 additions & 2 deletions test/tower_rollbar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ defmodule TowerRollbarTest do
"trace" => %{
"exception" => %{
"class" => "(exit)",
"message" => "abnormal"
"message" => ":abnormal"
},
"frames" => frames
}
Expand Down Expand Up @@ -327,7 +327,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 3db4f26

Please sign in to comment.