Splode-based error handling for Jido.AI.
Provides structured error types for AI operations including:
- API errors (rate limits, authentication, transient failures)
- Validation errors
- Runtime error envelope normalization and retryability policy
Summary
Functions
Builds a normalized AI runtime error envelope.
Normalizes arbitrary runtime error values into the canonical AI error envelope.
Ensures result payloads use {:ok, term, effects} or {:error, reason, effects} tuples.
Returns whether a result or error should be treated as retryable by runtime policy.
Serializes a runtime error term as the canonical AI runtime error 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
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.AI.Error.Validation | Jido.AI.Error.API | Splode.Error.Unknown
@type error_class() :: :validation | :api | :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 error_envelope(atom(), String.t(), map(), boolean()) :: error_envelope()
Builds a normalized AI runtime error envelope.
The envelope is the package-owned caller-visible contract used by tool, LLM, directive, and signal result paths.
@spec normalize(term(), atom(), String.t(), map()) :: error_envelope()
Normalizes arbitrary runtime error values into the canonical AI error envelope.
@spec normalize_result(term(), atom(), String.t()) :: {:ok, term(), [term()]} | {:error, error_envelope(), [term()]}
Ensures result payloads use {:ok, term, effects} or {:error, reason, effects} tuples.
Returns whether a result or error should be treated as retryable by runtime policy.
@spec to_map(term()) :: error_envelope()
Serializes a runtime error term as the canonical AI runtime error map.
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.AI.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