AshHooks.Errors (AshHooks v3.3.0)

Copy Markdown View Source

Splode error hierarchy for ash_hooks.

Inbound authentication and configuration failures have class :invalid. Custody availability failures have class :unknown. Unrecognized reasons become contents-free UnknownError values.

Summary

Functions

Maps a provider callback's reason (the {:error, reason} shape the behavior returns) to its Splode error. Known provider atoms pass opts through to exception/1; classified package errors pass through unchanged.

Calls the function for each leaf error and returns a nested map grouped by error path. See Splode.traverse_errors/2 for the traversal contract.

Returns the value from {:ok, value} or :ok. Raises a converted error for {:error, error} or :error, and ArgumentError for other result shapes.

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() :: AshHooks.Errors.Unknown | AshHooks.Errors.Invalid

error_class()

@type error_class() :: :unknown | :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

from_reason(error, opts)

@spec from_reason(term(), Keyword.t()) :: struct()

Maps a provider callback's reason (the {:error, reason} shape the behavior returns) to its Splode error. Known provider atoms pass opts through to exception/1; classified package errors pass through unchanged.

Unmapped reasons become a contents-free UnknownError; backend terms are never included in that error.

splode_error?(arg1, splode)

traverse_errors(error_or_errors, fun)

@spec traverse_errors(term(), (struct() -> term())) :: map()

Calls the function for each leaf error and returns a nested map grouped by error path. See Splode.traverse_errors/2 for the traversal contract.

unwrap!(result, opts \\ nil)

@spec unwrap!(term(), keyword() | nil) :: term()

Returns the value from {:ok, value} or :ok. Raises a converted error for {:error, error} or :error, and ArgumentError for other result shapes.

Accepts :error_opts for error conversion and :unknown_error_opts when the result is :error. See Splode for the error-conversion contract.