From a6a9aca27db9e37ffd2d940b5f56b4b6ce1fb4d8 Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:02:49 -0300 Subject: [PATCH] fix: support tuple value in error message --- lib/tower_rollbar/rollbar/item.ex | 14 +++++--------- test/tower_rollbar_test.exs | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/tower_rollbar/rollbar/item.ex b/lib/tower_rollbar/rollbar/item.ex index dd19059..22bacd0 100644 --- a/lib/tower_rollbar/rollbar/item.ex +++ b/lib/tower_rollbar/rollbar/item.ex @@ -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))) @@ -42,7 +35,7 @@ defmodule TowerRollbar.Rollbar.Item do "frames" => frames(stacktrace), "exception" => %{ "class" => class, - "message" => reason + "message" => string_or_inspect(reason) } } } @@ -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 diff --git a/test/tower_rollbar_test.exs b/test/tower_rollbar_test.exs index e53043e..b95cae0 100644 --- a/test/tower_rollbar_test.exs +++ b/test/tower_rollbar_test.exs @@ -127,7 +127,7 @@ defmodule TowerRollbarTest do "trace" => %{ "exception" => %{ "class" => "(exit)", - "message" => "abnormal" + "message" => ":abnormal" }, "frames" => frames } @@ -301,7 +301,7 @@ defmodule TowerRollbarTest do "trace" => %{ "exception" => %{ "class" => "(exit)", - "message" => "abnormal" + "message" => ":abnormal" }, # Plug.Cowboy doesn't provide stacktrace for exits "frames" => []