Unified error handling for the Jido ecosystem using Splode.
Error Types
Six consolidated error types cover all failure scenarios:
| Error | Use Case |
|---|---|
ValidationError | Invalid inputs, actions, sensors, configs |
ExecutionError | Runtime failures during execution or planning |
RoutingError | Signal routing and dispatch failures |
TimeoutError | Operation timeouts |
CompensationError | Saga compensation failures |
InternalError | Unexpected system failures |
Usage
# Validation failures (with optional kind)
Jido.Error.validation_error("Invalid email", kind: :input, field: :email)
Jido.Error.validation_error("Unknown action", kind: :action, action: MyAction)
# Execution failures (with optional phase)
Jido.Error.execution_error("Action failed", phase: :run)
Jido.Error.execution_error("Planning failed", phase: :planning)
# Routing/dispatch failures
Jido.Error.routing_error("No handler", target: "user.created")
# Timeouts
Jido.Error.timeout_error("Timed out", timeout: 5000)
# Internal errors
Jido.Error.internal_error("Unexpected failure")Splode Error Classes
Errors are classified for aggregation (in order of precedence):
:invalid- Validation failures:execution- Runtime failures:routing- Routing/dispatch failures:timeout- Timeouts:internal- Unexpected failures
Summary
Functions
Creates a compensation error.
Creates an execution error.
Extracts the message string from a nested error structure.
Formats a NimbleOptions configuration error.
Formats a NimbleOptions validation error for parameters.
Creates an internal error.
Returns whether an error is safe to retry by default.
Creates a routing error.
Creates a timeout error.
Converts an error into a stable, public map.
Traverses errors, calling fun for each leaf error, and returns a nested
map of results grouped by each error's path.
Raises an error if the result is an error, otherwise returns the result
Creates a validation error.
Types
@type class() :: %{ :__struct__ => class_module(), :__exception__ => true, :errors => [t()], :class => error_class(), :bread_crumbs => [String.t()], :vars => Keyword.t(), :stacktrace => Splode.Stacktrace.t() | nil, :context => map(), optional(atom()) => any() }
@type class_module() ::
Jido.Error.Internal
| Jido.Error.Timeout
| Jido.Error.Routing
| Jido.Error.Execution
| Jido.Error.Invalid
| Splode.Error.Unknown
@type error_class() ::
:internal | :timeout | :routing | :execution | :invalid | :unknown
@type t() :: %{ :__struct__ => module(), :__exception__ => true, :class => error_class(), :bread_crumbs => [String.t()], :vars => Keyword.t(), :stacktrace => Splode.Stacktrace.t() | nil, :context => map(), optional(atom()) => any() }
Functions
@spec compensation_error(String.t(), keyword() | map()) :: Jido.Error.CompensationError.t()
Creates a compensation error.
Options
:original_error- The error that triggered compensation:compensated- Whether compensation succeeded (default: false):result- Result from successful compensation:details- Additional context map
@spec execution_error(String.t(), keyword() | map()) :: Jido.Error.ExecutionError.t()
Creates an execution error.
Options
:phase- Where failure occurred::execution,:planning:details- Additional context map- Any other keys are merged into
details
Extracts the message string from a nested error structure.
Formats a NimbleOptions configuration error.
Formats a NimbleOptions validation error for parameters.
@spec internal_error(String.t(), keyword() | map()) :: Jido.Error.InternalError.t()
Creates an internal error.
Options
:details- Additional context map
Returns whether an error is safe to retry by default.
Explicit :retry, :retryable, and :retryable? boolean hints in structured
details override the default classification.
@spec routing_error(String.t(), keyword() | map()) :: Jido.Error.RoutingError.t()
Creates a routing error.
Options
:target- The intended routing target:details- Additional context map
@spec timeout_error(String.t(), keyword() | map()) :: Jido.Error.TimeoutError.t()
Creates a timeout error.
Options
:timeout- The timeout value in milliseconds:details- Additional context map
Converts an error into a stable, public map.
The returned map is suitable for transport and reporting boundaries. It includes bounded, sanitized details and never includes stacktraces by default.
Traverses errors, calling fun for each leaf error, and returns a nested
map of results grouped by each error's path.
See Splode.traverse_errors/2 for full documentation.
Example
iex> Elixir.Jido.Error.traverse_errors(error, fn error ->
...> Exception.message(error)
...> end)
%{name: ["name is required"]}
Raises an error if the result is an error, otherwise returns the result
Alternatively, you can use the defsplode macro, which does this automatically.
Options
:error_opts- Options to pass toto_error/2when converting the returned error:unknown_error_opts- Options to pass to the unknown error if the function returns only:error. not necessary if your function always returns{:error, error}.
Examples
def function(arg) do
case do_something(arg) do
:success -> :ok
{:success, result} -> {:ok, result}
{:error, error} -> {:error, error}
endend
def function!(arg) do
YourErrors.unwrap!(function(arg))end
@spec validation_error(String.t(), keyword() | map()) :: Jido.Error.ValidationError.t()
Creates a validation error.
Options
:kind- Category::input,:action,:sensor,:config:subject- The invalid value:field- Alias for:subject(for input validation):action- Alias for:subjectwithkind: :action:sensor- Alias for:subjectwithkind: :sensor:details- Additional context map
Examples
validation_error("Invalid email", field: :email)
validation_error("Unknown action", kind: :action, subject: MyAction)