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

test: better cover :erlang.error/1 #80

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
33 changes: 30 additions & 3 deletions test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
assert [_ | _] = stacktrace
end

test "reports a raise" do
test "reports as an :error an Erlang error Elixir can normalize" do
capture_log(fn ->
in_unlinked_process(fn ->
raise "error inside process"
:erlang.error(:badarith)
end)
end)

Expand All @@ -55,7 +55,34 @@
datetime: datetime,
level: :error,
kind: :error,
reason: %RuntimeError{message: "error inside process"},
reason: %ArithmeticError{message: "bad argument in arithmetic expression"},
stacktrace: stacktrace
}
] = reported_events()
)

assert String.length(id) == 36
assert recent_datetime?(datetime)
assert [_ | _] = stacktrace
end

test "reports as an :exit an Erlang error Elixir cannot normalize" do
capture_log(fn ->
in_unlinked_process(fn ->
:erlang.error("a naked erlang error")
end)
end)

assert_eventually(
[
%{
id: id,
datetime: datetime,
level: :error,
# Why ends up as exit?
# https://github.com/elixir-lang/elixir/blob/78f63d08313677a680868685701ae79a2459dcc1/lib/logger/lib/logger/translator.ex#L663-L665
kind: :exit,
reason: "a naked erlang error",
stacktrace: stacktrace
}
] = reported_events()
Expand Down Expand Up @@ -619,7 +646,7 @@

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

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.15)

the call to //2 will fail with ArithmeticError

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17)

the call to //2 will fail with ArithmeticError

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.15)

the call to //2 will fail with ArithmeticError

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17)

the call to //2 will fail with ArithmeticError

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.15)

the call to //2 will fail with ArithmeticError

Check warning on line 649 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17)

the call to //2 will fail with ArithmeticError
end)

in_unlinked_process(fn ->
Expand Down