# `Skeg.Error`

An error from the server or from the client.

What an error proves about the request decides what the caller may do
next. `kind` says it:

  * `:connect_failed`, `:invalid_argument`, `:not_sent` - no byte of the
    request reached the server, so nothing was applied.
    `nothing_applied?/1` is true only for these.
  * `:server` - the server answered with an error. It may have applied
    part of the request before failing. `code` is the first word of the
    reply (`"ERR"`, `"WRONGPASS"`, `"BACKPRESSURE"`...), `message` the rest.
    Inside a batch reply an error is one element among the results.
  * `:outcome_unknown` - no complete answer arrived. The request may have
    been applied in full, in part, or not at all. The connection is closed.
  * `:unexpected_reply` - the server answered with a reply of a shape the
    call does not expect; `reason` holds it.

Send a write again only when `nothing_applied?/1` is true, or after reading
back what the server holds. Commands are never retried automatically.

`reason` details the client-side kinds:

  * `:not_sent` - `:closed`, `:deadline_exceeded` (the deadline passed
    while the request waited behind others), `:unsolicited_data` (the
    server sent bytes nobody asked for, so the connection was closed), or
    `{:reconnect, error}`
  * `:outcome_unknown` - `:timeout`, `:peer_closed`, `{:transport, posix}`,
    `{:protocol, decode_reason}`, `:trailing_data` (more replies than
    requests), `:reply_too_large`, or `{:owner_exit, reason}`
  * `:connect_failed` - the `:gen_tcp` reason
  * `:invalid_argument` - a description of the limit exceeded

# `kind`

```elixir
@type kind() ::
  :server
  | :connect_failed
  | :invalid_argument
  | :not_sent
  | :outcome_unknown
  | :unexpected_reply
```

# `t`

```elixir
@type t() :: %Skeg.Error{
  __exception__: term(),
  code: String.t() | nil,
  kind: kind(),
  message: String.t(),
  reason: term()
}
```

# `nothing_applied?`

```elixir
@spec nothing_applied?(t()) :: boolean()
```

Whether the error proves that the server applied nothing: the connection
was never opened, or the request was refused or dropped before sending.

# `temporary?`

```elixir
@spec temporary?(t()) :: boolean()
```

Whether the server described its refusal as temporary (`BACKPRESSURE`, or
`RATELIMITED` from a tenant backend), so the same request may succeed
later. This says nothing about effects already applied: combine it with
`nothing_applied?/1`, or with a request that is safe to repeat.

---

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