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

class()

@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()
}

class_module()

@type class_module() ::
  Internal | Timeout | Routing | Execution | Invalid | Splode.Error.Unknown

detail_map()

@type detail_map() :: map()

error_class()

@type error_class() ::
  :internal | :timeout | :routing | :execution | :invalid | :unknown

t()

@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

dispatch_error(message, details \\ %{})

@spec dispatch_error(String.t(), keyword() | map()) :: Exception.t()

Creates a dispatch error for signal dispatch failures.

execution_error(message, details \\ %{})

@spec execution_error(String.t(), keyword() | map()) :: Exception.t()

Creates an execution error for signal processing failures.

format_nimble_config_error(error, module_type, module)

@spec format_nimble_config_error(
  NimbleOptions.ValidationError.t() | any(),
  String.t(),
  module()
) :: String.t()

Formats a NimbleOptions validation error for configuration validation.

format_nimble_validation_error(error, module_type, module)

@spec format_nimble_validation_error(
  NimbleOptions.ValidationError.t() | any(),
  String.t(),
  module()
) :: String.t()

Formats a NimbleOptions validation error for runtime parameter validation.

internal_error(message, details \\ %{})

@spec internal_error(String.t(), keyword() | map()) :: Exception.t()

Creates an internal error.

normalize(error)

@spec normalize(term()) :: Exception.t()

Normalizes a foreign failure into a package-local error.

retryable?(arg1)

@spec retryable?(term()) :: boolean()

Returns whether a failure is retryable according to the package policy.

routing_error(message, details \\ %{})

@spec routing_error(String.t(), keyword() | map()) :: Exception.t()

Creates a routing error for signal routing failures.

splode_error?(arg1, splode)

timeout_error(message, details \\ %{})

@spec timeout_error(String.t(), keyword() | map()) :: Exception.t()

Creates a timeout error for signal processing timeouts.

to_map(error)

@spec to_map(term()) :: map()

Serializes a public error payload through the canonical package adapter.

traverse_errors(error_or_errors, fun)

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"]}

type(error)

@spec type(term()) :: atom()

Returns the stable machine-readable error type.

unwrap!(result, opts \\ nil)

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 to to_error/2 when 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}
end

end

def function!(arg) do

YourErrors.unwrap!(function(arg))

end

validation_error(message, details \\ %{})

@spec validation_error(String.t(), keyword() | map()) :: Exception.t()

Creates a validation error for invalid input parameters.