Jido. Signal. Error
(Jido Signal v2.2.0)
View Source
Canonical error taxonomy, normalization, retryability, and public serialization for Jido Signal.
Use this module to create package-local exceptions, normalize foreign failures,
and serialize public error payloads through to_map/1.
Summary
Functions
Creates a dispatch error for signal dispatch failures.
Creates an execution error for signal processing failures.
Formats a NimbleOptions validation error for configuration validation.
Formats a NimbleOptions validation error for runtime parameter validation.
Creates an internal error.
Normalizes a foreign failure into a package-local error.
Returns whether a failure is retryable according to the package policy.
Creates a routing error for signal routing failures.
Creates a timeout error for signal processing timeouts.
Serializes a public error payload through the canonical package adapter.
Traverses errors, calling fun for each leaf error, and returns a nested
map of results grouped by each error's path.
Returns the stable machine-readable error type.
Raises an error if the result is an error, otherwise returns the result
Creates a validation error for invalid input parameters.
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() ::
Internal | Timeout | Routing | Execution | Invalid | Splode.Error.Unknown
@type detail_map() :: map()
@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 dispatch_error(String.t(), keyword() | map()) :: Exception.t()
Creates a dispatch error for signal dispatch failures.
@spec execution_error(String.t(), keyword() | map()) :: Exception.t()
Creates an execution error for signal processing failures.
@spec format_nimble_config_error( NimbleOptions.ValidationError.t() | any(), String.t(), module() ) :: String.t()
Formats a NimbleOptions validation error for configuration validation.
@spec format_nimble_validation_error( NimbleOptions.ValidationError.t() | any(), String.t(), module() ) :: String.t()
Formats a NimbleOptions validation error for runtime parameter validation.
@spec internal_error(String.t(), keyword() | map()) :: Exception.t()
Creates an internal error.
@spec normalize(term()) :: Exception.t()
Normalizes a foreign failure into a package-local error.
Returns whether a failure is retryable according to the package policy.
@spec routing_error(String.t(), keyword() | map()) :: Exception.t()
Creates a routing error for signal routing failures.
@spec timeout_error(String.t(), keyword() | map()) :: Exception.t()
Creates a timeout error for signal processing timeouts.
Serializes a public error payload through the canonical package adapter.
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.Signal.Error.traverse_errors(error, fn error ->
...> Exception.message(error)
...> end)
%{name: ["name is required"]}
Returns the stable machine-readable error type.
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()) :: Exception.t()
Creates a validation error for invalid input parameters.