Skip to content

Commit

Permalink
feat: include original error in Tower.ReportEventError message
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Sep 17, 2024
1 parent e695db2 commit bf82434
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/tower.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ defmodule Tower do
"""

defmodule ReportEventError do
defexception [:original_exception, :reporter]
defexception [:original, :reporter]

def message(%__MODULE__{reporter: reporter}) do
"An error occurred while trying to report an event with reporter #{reporter}"
def message(%__MODULE__{reporter: reporter, original: {kind, reason, stacktrace}}) do
"""
The following error occurred while trying to report an event with reporter #{reporter}:
#{Exception.format(kind, reason, stacktrace)}
"""
end
end

Expand Down Expand Up @@ -446,7 +450,9 @@ defmodule Tower do
reporter.report_event(event)
rescue
exception ->
raise ReportEventError, reporter: reporter, original_exception: exception
raise ReportEventError,
reporter: reporter,
original: {:error, exception, __STACKTRACE__}
end
end)
end
Expand Down
2 changes: 1 addition & 1 deletion test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ defmodule TowerTest do
kind: :error,
reason: %Tower.ReportEventError{
reporter: BuggyReporter,
original_exception: %RuntimeError{message: "I have a bug"}
original: {:error, %RuntimeError{message: "I have a bug"}, [_ | _]}
},
stacktrace: stacktrace1
},
Expand Down

0 comments on commit bf82434

Please sign in to comment.