Jido.Composer.Error (Jido Composer v0.6.0)

Copy Markdown View Source

Structured error types for Jido Composer using Splode.

Error Classes

ClassUse Case
:invalidValidation and configuration errors
:transitionFSM transition failures
:executionNode execution failures
:orchestrationLLM/tool interaction errors

Summary

Functions

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

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() ::
  Jido.Composer.Error.Unknown
  | Jido.Composer.Error.Orchestration
  | Jido.Composer.Error.Communication
  | Jido.Composer.Error.Execution
  | Jido.Composer.Error.Transition
  | Jido.Composer.Error.Invalid

error_class()

@type error_class() ::
  :unknown
  | :orchestration
  | :communication
  | :execution
  | :transition
  | :invalid

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

communication_error(message, opts \\ [])

@spec communication_error(
  String.t(),
  keyword()
) :: Jido.Composer.Error.CommunicationError.t()

execution_error(message, opts \\ [])

@spec execution_error(
  String.t(),
  keyword()
) :: Jido.Composer.Error.ExecutionError.t()

orchestration_error(message, opts \\ [])

@spec orchestration_error(
  String.t(),
  keyword()
) :: Jido.Composer.Error.OrchestrationError.t()

splode_error?(arg1, splode)

transition_error(message, opts \\ [])

@spec transition_error(
  String.t(),
  keyword()
) :: Jido.Composer.Error.TransitionError.t()

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.Composer.Error.traverse_errors(error, fn error ->
...>   Exception.message(error)
...> end)
%{name: ["name is required"]}

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, opts \\ [])

@spec validation_error(
  String.t(),
  keyword()
) :: Jido.Composer.Error.ValidationError.t()