# `Opsmaru.Incus.StatusError`
[🔗](https://github.com/upmaru/opsmaru-incus/blob/v0.1.0/lib/opsmaru/incus/status_error.ex#L1)

Pure immutable counterpart of the native `shared/api.StatusError` value.

`new/2` is the constructor counterpart of `StatusErrorf`. It takes an
already-formatted message and does not emulate Go `fmt` verbs: the native
no-argument path keeps the format string literally, so a message such as
`"100%"` stays `"100%"` and callers preformat before calling `new/2`.

`error/1` returns the message when non-empty, otherwise the exact embedded
`net/http.StatusText` table ("" for unknown codes). The table is compiled in;
there is no network or runtime lookup. `status/1` returns the status code.

`match/2` and `check/2` are the counterparts of `StatusErrorMatch` and
`StatusErrorCheck`. Go `errors.As` unwrapping has no Elixir equivalent: only
a direct `%StatusError{}` term matches; wrapped terms,
`Opsmaru.Incus.Error` values and any other term never match, even when one
wraps or carries a status code.

The value is pure: no logging, atoms from input, processes, I/O or backend
contact. `Inspect` redacts the message like `Opsmaru.Incus.Error`.

# `t`

```elixir
@type t() :: %Opsmaru.Incus.StatusError{message: term(), status: term()}
```

# `check`

Counterpart of `StatusErrorCheck`; invalid code lists behave as in `match/2`.

# `error`

The message, or the native status text for the status when the message is empty.
Values outside the `new/2` bounds, including directly built structs, return
`{:error, %Error{kind: :invalid_input}}`.

# `match`

Counterpart of `StatusErrorMatch`.

Returns `{status, true}` when the term is a direct `%StatusError{}` and the
codes list is empty or contains its status, otherwise `{-1, false}`. Invalid
code lists return `{:error, %Error{kind: :invalid_input}}` and never raise.

# `new`

Constructs a `t/0` from an already-formatted message.

Returns `{:ok, %StatusError{}}` on success and
`{:error, %Error{kind: :invalid_input}}` (and never raises) when the status
is not an integer in Go int64 range or the message is not a binary of at
most 64 KiB.

# `status`

The HTTP status code; invalid values behave as in `error/1`.

---

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