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 error grouping issue #133

Merged
merged 5 commits into from
Feb 28, 2025
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/error_tracker/schemas/stacktrace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule ErrorTracker.Stacktrace do
application, just the first line.
"""
def source(stack = %__MODULE__{}) do
client_app = Application.fetch_env!(:error_tracker, :otp_app)
client_app = Application.fetch_env!(:error_tracker, :otp_app) |> to_string()

Enum.find(stack.lines, &(&1.application == client_app)) || List.first(stack.lines)
end
Expand Down
20 changes: 15 additions & 5 deletions test/error_tracker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ defmodule ErrorTrackerTest do
alias ErrorTracker.Error
alias ErrorTracker.Occurrence

@relative_file_path Path.relative_to(__ENV__.file, File.cwd!())
# We use this file path because for some reason the test scripts are not
# handled as part of the application, so the last line of the app executed is
# on the case module.
@relative_file_path "test/support/case.ex"

describe inspect(&ErrorTracker.report/3) do
setup context do
Expand All @@ -29,18 +32,25 @@ defmodule ErrorTrackerTest do
test "reports badarith errors" do
string_var = to_string(1)

%Occurrence{error: error = %Error{}} =
%Occurrence{error: error = %Error{}, stacktrace: %{lines: [last_line | _]}} =
report_error(fn -> 1 + string_var end)

assert error.kind == to_string(ArithmeticError)
assert error.reason == "bad argument in arithmetic expression"

# Elixir 1.17.0 reports these errors differently than previous versions
if Version.compare(System.version(), "1.17.0") == :lt do
assert error.source_line =~ @relative_file_path
assert last_line.module == "ErrorTrackerTest"
assert last_line.function =~ "&ErrorTracker.report/3 reports badarith errors"
assert last_line.arity == 1
assert last_line.file
assert last_line.line
else
assert error.source_function == "erlang.+/2"
assert error.source_line == "(nofile)"
assert last_line.module == "erlang"
assert last_line.function == "+"
assert last_line.arity == 2
refute last_line.file
refute last_line.line
end
end

Expand Down