# `Reactor.Error`
[🔗](https://github.com/ash-project/reactor/blob/main/lib/reactor/error.ex/#L6)

Uses `splode` to manage various classes of error.

# `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() ::
  Reactor.Error.Validation
  | Reactor.Error.Unknown
  | Reactor.Error.Invalid
  | Reactor.Error.Internal
```

# `error_class`

```elixir
@type error_class() :: :validation | :unknown | :invalid | :reactor
```

# `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()
}
```

# `__using__`
*macro* 

```elixir
@spec __using__(keyword()) :: Macro.output()
```

Convenience wrapper around `use Splode.Error`

# `fetch_error`

```elixir
@spec fetch_error(Exception.t(), module()) :: {:ok, Exception.t()} | :error
```

Recursively searches through nested reactor errors for the first instance of
the provided module.

# `find_errors`

```elixir
@spec find_errors(Exception.t(), module()) :: [Exception.t()]
```

Recursively searches through nested reactor errors and returns any errors
which match the provided module name.

# `splode_error?`

# `traverse_errors`

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

# `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*
