Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap worker crashes and tuples in exceptions
This makes several significant changes to how crahes, errors and timeouts are reported from `perform/1` calls: * Timeouts are wrapped in `Oban.TimeoutError` * Error and discard tuples are wrapped in `Oban.PerformError` * Exits and throws are wrapped in `Oban.CrashError` * Stacktraces are only included from code that is rescued or caught, not from error tuples or timeouts. The goal is improve error formatting within a job's error array and to make error reporting to external services like Sentry entirely consistent. Fixes #305
- Loading branch information
Showing
8 changed files
with
81 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Oban.CrashError do | ||
@moduledoc """ | ||
Wraps unhandled exits and throws that occur during job execution. | ||
""" | ||
|
||
defexception [:message] | ||
|
||
@impl Exception | ||
def exception({kind, reason, stacktrace}) do | ||
%__MODULE__{message: Exception.format_banner(kind, reason, stacktrace)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Oban.PerformError do | ||
@moduledoc """ | ||
Wraps the reason returned by `{:error, reason}`, `{:discard, reason}` in a proper exception. | ||
""" | ||
|
||
alias Oban.Worker | ||
|
||
defexception [:message] | ||
|
||
@impl Exception | ||
def exception({worker, reason}) do | ||
%__MODULE__{message: "#{Worker.to_string(worker)} failed with #{inspect(reason)}"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Oban.TimeoutError do | ||
@moduledoc """ | ||
Returned when a job is terminated early due to a custom timeout. | ||
""" | ||
|
||
alias Oban.Worker | ||
|
||
defexception [:message] | ||
|
||
@impl Exception | ||
def exception({worker, timeout}) do | ||
%__MODULE__{message: "#{Worker.to_string(worker)} timed out after #{timeout}ms"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters