# `Jidoka.Error`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/error.ex#L1)

Splode-backed error helpers for Jidoka.

Runtime-facing APIs should return these errors instead of leaking raw atoms,
tuples, or third-party exception structs. Lower-level constructors may still
return library-native validation details when that is the precise contract.

# `category`

```elixir
@type category() :: :validation | :configuration | :execution | :internal | :unknown
```

# `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() ::
  Jidoka.Error.Internal
  | Jidoka.Error.Config
  | Jidoka.Error.Execution
  | Jidoka.Error.Invalid
  | Splode.Error.Unknown
```

# `context`

```elixir
@type context() :: keyword() | map()
```

# `error_class`

```elixir
@type error_class() :: :internal | :config | :execution | :invalid | :unknown
```

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

# `category`

```elixir
@spec category(term()) :: category()
```

Returns the Jidoka error category for a normalized exception or aggregate error.

# `config_error`

```elixir
@spec config_error(String.t(), keyword() | map()) :: Exception.t()
```

Builds a Splode-backed configuration error.

# `execution_error`

```elixir
@spec execution_error(String.t(), keyword() | map()) :: Exception.t()
```

Builds a Splode-backed execution error.

# `format`

```elixir
@spec format(term()) :: String.t()
```

Formats a Jidoka/Splode error into a short human-readable message.

# `normalize`

```elixir
@spec normalize(term(), context()) :: Exception.t()
```

Normalizes arbitrary error terms into a Jidoka/Splode exception.

# `normalized?`

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

Returns whether an error term is already a Jidoka/Splode error.

# `splode_error?`

# `to_map`

```elixir
@spec to_map(term()) :: map()
```

Converts a Jidoka/Splode error into a serializable map.

# `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.Jidoka.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

# `validation_error`

```elixir
@spec validation_error(String.t(), keyword() | map()) :: Exception.t()
```

Builds a Splode-backed validation error.

---

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