Opsmaru.Incus.StatusError (opsmaru_incus v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

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}}.

Counterpart of StatusErrorMatch.

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

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

Types

t()

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

Functions

check(term, codes \\ [])

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

error(arg1)

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(arg1, codes \\ [])

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(status, message)

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(arg1)

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