Skip to content

Commit

Permalink
non-string throws
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jun 4, 2024
1 parent ca66d6c commit 405e0f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/tower.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ defmodule Tower do
end)
end

def report(type, reason, stacktrace, meta \\ %{})
when is_atom(type) and is_binary(reason) and is_list(stacktrace) do
def report(type, reason, stacktrace, meta \\ %{}) when is_atom(type) and is_list(stacktrace) do
reporters()
|> Enum.each(fn reporter ->
reporter.report(type, reason, stacktrace, meta)
Expand Down
3 changes: 1 addition & 2 deletions lib/tower/ephemeral_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ defmodule Tower.EphemeralReporter do
)
end

def report(type, reason, stacktrace, meta \\ %{})
when is_atom(type) and is_binary(reason) and is_list(stacktrace) do
def report(type, reason, stacktrace, meta \\ %{}) when is_atom(type) and is_list(stacktrace) do
Agent.update(
__MODULE__,
fn errors ->
Expand Down
23 changes: 22 additions & 1 deletion test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule TowerTest do
assert is_list(stacktrace)
end

test "reports a throw" do
test "reports a thrown string" do
Tower.EphemeralReporter.start_link([])

in_unlinked_process(fn ->
Expand All @@ -58,6 +58,27 @@ defmodule TowerTest do
assert is_list(stacktrace)
end

test "reports a thrown non-string" do
Tower.EphemeralReporter.start_link([])

in_unlinked_process(fn ->
throw(something: "here")
end)

assert(
[
%{
time: _,
type: :nocatch,
reason: [something: "here"],
stacktrace: stacktrace
}
] = Tower.EphemeralReporter.errors()
)

assert is_list(stacktrace)
end

test "reports arithmetic error" do
Tower.EphemeralReporter.start_link([])

Expand Down

0 comments on commit 405e0f4

Please sign in to comment.