View Source Ash.Error (ash v3.4.47)
Tools and utilities used by Ash to manage and conform errors
Summary
Functions
Returns whether or not a term is an Ash.Error type.
Converts errors into a single String.t
.
This function prepends the provided path to any existing path on the errors.
Converts a value to an Ash exception.
Converts a value to an Ash.Error type.
Raises an error if the result is an error, otherwise returns the result
Types
@type ash_error() :: Exception.t()
@type ash_error_subject() :: Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t()
@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() ::
Ash.Error.Unknown
| Ash.Error.Framework
| Ash.Error.Invalid
| Ash.Error.Forbidden
@type error_class() :: :unknown | :framework | :invalid | :forbidden
@type error_input() :: ash_error() | error_keyword() | String.t() | ash_error_subject() | Exception.t() | any()
@type error_keyword() :: [error_keyword_option()]
@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
Returns whether or not a term is an Ash.Error type.
Converts errors into a single String.t
.
@spec set_path(ash_error() | [ash_error()], path_input()) :: ash_error() | [ash_error()]
@spec set_path(ash_error_subject(), path_input()) :: ash_error_subject()
This function prepends the provided path to any existing path on the errors.
@spec to_ash_error( error_input() | [error_input()], Exception.stacktrace() | nil, Keyword.t() ) :: ash_error() | [ash_error()]
Converts a value to an Ash exception.
The supported inputs to this function can be provided to various places,
like Ash.Query.add_error/2
, Ash.Changeset.add_error/2
and Ash.ActionInput.add_error/2
.
Additionally, any place that you can return an error you can return instead a valid error input.
See the error handling guide for more.
@spec to_error_class( ash_error_subject() | term() | [ash_error_subject()] | [term()], Keyword.t() ) :: t()
Converts a value to an Ash.Error type.
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/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