Jido.Flow.Error (Jido Action v3.0.0-beta.12)

View Source

Defines and normalizes errors owned by Jido Flows.

Flow errors cover authoring data, compilation, native Runic coordination, and Flow execution state. An Action failure inside a Flow keeps its original Jido.Action.Error type. This module can merge those Action errors when one Flow operation has more than one failure.

Summary

Functions

Creates a Flow execution failure.

Creates one failure for a Flow operation with failed Runic runnables.

Creates an internal Flow error.

Creates an invalid Flow execution input or state error.

Returns whether a Flow or Action error is retryable.

Creates a Flow timeout error.

Converts a Flow or Action error into its 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 an invalid Flow definition error.

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.Flow.Error.Internal
  | Jido.Flow.Error.Execution
  | Jido.Flow.Error.Invalid
  | Splode.Error.Unknown

details_input()

@type details_input() :: map() | keyword()

error_class()

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

error_map()

@type error_map() :: Jido.Action.Error.error_map()

runnable_failure()

@type runnable_failure() :: %{
  node: term(),
  runnable_id: Runic.Identity.t() | integer(),
  error: Exception.t()
}

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

execution_error(message, details \\ %{})

Creates a Flow execution failure.

flow_failure(flow, failures)

Creates one failure for a Flow operation with failed Runic runnables.

internal_error(message, details \\ %{})

@spec internal_error(String.t(), details_input()) :: Jido.Flow.Error.InternalError.t()

Creates an internal Flow error.

invalid_execution_error(message, details \\ %{})

@spec invalid_execution_error(String.t(), details_input()) ::
  Jido.Flow.Error.InvalidExecutionError.t()

Creates an invalid Flow execution input or state error.

retryable?(error)

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

Returns whether a Flow or Action error is retryable.

splode_error?(arg1, splode)

timeout_error(message, details \\ %{})

@spec timeout_error(String.t(), details_input()) :: Jido.Flow.Error.TimeoutError.t()

Creates a Flow timeout error.

to_map(error)

@spec to_map(term()) :: error_map()

Converts a Flow or Action error into its public map.

Detail values stay unchanged. A caller that sends the map through JSON or another transport must convert its own detail values for that transport. Nested Flow and Action errors become their public maps.

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.Flow.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, details \\ %{})

Creates an invalid Flow definition error.