Absurd.Error exception (absurd v0.2.1)

Copy Markdown View Source

The public error returned by Absurd operations.

Errors keep a stable :kind and human-readable :message while retaining bounded diagnostic context. Database errors may also expose their SQLSTATE without requiring callers to match on Postgrex internals.

Examples

iex> error = Absurd.Error.new(:validation, "queue must not be empty")
iex> {error.kind, Exception.message(error)}
{:validation, "queue must not be empty"}

Summary

Types

The stable category of an Absurd error.

t()

A public Absurd error value.

Functions

Converts a database exception into the public error envelope.

Builds an error with optional diagnostic fields.

Types

kind()

@type kind() ::
  :validation
  | :configuration
  | :database
  | :ambiguous
  | :protocol
  | :schema_incompatible
  | :cancelled
  | :failed_run
  | :timeout
  | :unknown_task

The stable category of an Absurd error.

t()

@type t() :: %Absurd.Error{
  __exception__: term(),
  cause: term(),
  kind: kind(),
  message: String.t(),
  metadata: map(),
  operation: atom() | nil,
  sqlstate: String.t() | nil
}

A public Absurd error value.

Functions

from_exception(exception, operation \\ nil, options \\ [])

@spec from_exception(Exception.t(), atom() | nil, keyword()) :: t()

Converts a database exception into the public error envelope.

Absurd SQLSTATE AB001 is classified as :cancelled; AB002 is classified as :failed_run. Pass ambiguous?: true for a mutating operation whose established connection was lost before its outcome was observed. Connection checkout timeouts are never ambiguous because no query was issued.

new(kind, message, options \\ [])

@spec new(kind(), String.t(), keyword()) :: t()

Builds an error with optional diagnostic fields.

Supported options are :operation, :sqlstate, :cause, and :metadata.