Skip to content
Draft
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
19 changes: 17 additions & 2 deletions lib/tower.ex
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ defmodule Tower do
reporter.report_event(event)
rescue
exception ->
async(fn ->
in_unlinked_task(fn ->
raise ReportEventError,
reporter: reporter,
original: {:error, exception, __STACKTRACE__}
Expand All @@ -573,7 +573,22 @@ defmodule Tower do
Application.fetch_env!(:tower, :reporters)
end

defp async(fun) do
def async(reporter, fun) do
in_unlinked_task(fn ->
try do
fun.()
rescue
exception ->
in_unlinked_task(fn ->
raise ReportEventError,
Copy link
Copy Markdown
Collaborator Author

@grzuy grzuy Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now I realize doesn't make sense as is: raising an error called ReporEventError from a function that is called async. async function can be called from a reporter report_event, but any other place too.

reporter: reporter,
original: {:error, exception, __STACKTRACE__}
end)
end
end)
end

defp in_unlinked_task(fun) do
Tower.TaskSupervisor
|> Task.Supervisor.start_child(fun)
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 @@ -588,7 +588,7 @@ defmodule TowerTest do

@impl true
def report_event(_event) do
raise "I have a bug"
Tower.async(__MODULE__, fn -> raise "I have a bug" end)
end
end

Expand Down