# `Huginn.Error`
[🔗](https://github.com/nyo16/huginn/blob/v0.6.0/lib/huginn/error.ex#L1)

The single error type returned (and raised) by Huginn.

Every public function returns `{:error, %Huginn.Error{}}` on failure, and the
bang/streaming variants raise it. Match on `:reason` to branch:

| `:reason` | Meaning | `:code` |
| --------- | ------- | ------- |
| `:server` | ClickHouse rejected or failed the query | ClickHouse error code |
| `:connection` | No usable connection (pool not ready, refused, unavailable) | gRPC status, if any |
| `:timeout` | The request deadline expired | gRPC status, if any |
| `:grpc` | Any other gRPC-level failure | gRPC status |
| `:decode` | The server output could not be parsed in the requested format | `nil` |
| `:unexpected_reply` | The server replied with something that is not a `Result` | `nil` |
| `:not_configured` | No pool is configured under the requested name | `nil` |

`:details` carries the original term (the ClickHouse exception, the
`GRPC.RPCError`, the decoder error, ...) for logging and debugging.

# `reason`

```elixir
@type reason() ::
  :server
  | :connection
  | :timeout
  | :grpc
  | :decode
  | :unexpected_reply
  | :not_configured
```

# `t`

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

# `wrap`

```elixir
@spec wrap(term()) :: t()
```

Normalizes any failure term produced by the transport or the server into a
`Huginn.Error`. An existing `Huginn.Error` is returned unchanged.

---

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