# `Ash.Error`
[🔗](https://github.com/ash-project/ash/blob/v3.17.0/lib/ash/error/error.ex#L5)

Tools and utilities used by Ash to manage and conform errors

# `ash_error`

```elixir
@type ash_error() :: Exception.t()
```

# `ash_error_subject`

```elixir
@type ash_error_subject() :: Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t()
```

# `class`

```elixir
@type class() :: %{
  :__struct__ =&gt; class_module(),
  :__exception__ =&gt; true,
  :errors =&gt; [t()],
  :class =&gt; error_class(),
  :bread_crumbs =&gt; [String.t()],
  :vars =&gt; Keyword.t(),
  :stacktrace =&gt; Splode.Stacktrace.t() | nil,
  :context =&gt; map(),
  optional(atom()) =&gt; any()
}
```

# `class_module`

```elixir
@type class_module() ::
  Ash.Error.Unknown
  | Ash.Error.Framework
  | Ash.Error.Invalid
  | Ash.Error.Forbidden
```

# `error_class`

```elixir
@type error_class() :: :unknown | :framework | :invalid | :forbidden
```

# `error_input`

```elixir
@type error_input() ::
  ash_error()
  | error_keyword()
  | String.t()
  | ash_error_subject()
  | Exception.t()
  | any()
```

# `error_keyword`

```elixir
@type error_keyword() :: [error_keyword_option()]
```

# `error_keyword_option`

```elixir
@type error_keyword_option() ::
  {:field, atom()}
  | {:fields, [atom()]}
  | {:value, term()}
  | {:message, String.t()}
  | {:path, [atom() | String.t()]}
```

# `path`

```elixir
@type path() :: [String.t() | atom() | integer()]
```

# `path_input`

```elixir
@type path_input() ::
  [String.t() | atom() | integer()] | String.t() | atom() | integer()
```

# `t`

```elixir
@type t() :: %{
  :__struct__ =&gt; module(),
  :__exception__ =&gt; true,
  :class =&gt; error_class(),
  :bread_crumbs =&gt; [String.t()],
  :vars =&gt; Keyword.t(),
  :stacktrace =&gt; Splode.Stacktrace.t() | nil,
  :context =&gt; map(),
  optional(atom()) =&gt; any()
}
```

# `ash_error?`

```elixir
@spec ash_error?(term()) :: boolean()
```

Returns whether or not a term is an Ash.Error type.

# `error_descriptions`

```elixir
@spec error_descriptions(term() | [term()]) :: String.t()
```

Converts errors into a single `String.t`.

# `set_path`

```elixir
@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.

# `splode_error?`

# `to_ash_error`

```elixir
@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](/documentation/development/error-handling.md) for more.

# `to_error_class`

```elixir
@spec to_error_class(
  ash_error_subject() | term() | [ash_error_subject()] | [term()],
  Keyword.t()
) :: t()
```

Converts a value to an Ash.Error type.

# `unwrap!`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
