Trebejo.Error (Trebejo v2.0.0)

Copy Markdown View Source

Typed error wrapper for Trebejo command failures.

Wraps the raw {:error, reason} from Arrea.Command (or any other source) into a %Trebejo.Error{} struct so callers can pattern-match on a single error type without inspecting raw exit codes or stderr strings.

Fields

  • :kind — atom describing the failure category (see kind/0).
  • :exit_status — integer exit code reported by the process, when available. nil for non-process errors (timeout, port crash).
  • :cmd — command line that was attempted (string).
  • :stderr — captured stderr (or merged output) for diagnostics, trimmed. nil if not captured.
  • :reason — raw underlying reason (atom, tuple, or string).
  • :duration_ms — wall-clock time spent before the error, in ms. Useful to distinguish a 31s timeout from a 30s+1ms timeout.

Kind taxonomy

kindwhen
:not_foundexit 127 — command not found
:permission_deniedexit 126 — binary exists but not executable
:invalid_argsexit 2/64/65 — bad arguments / syntax error
:timeoutcommand exceeded the configured timeout
:signalprocess killed by a signal (e.g. SIGTERM → 137)
:exit_nonzeronon-zero exit status that doesn't map to a more specific kind
:port_closedthe streaming port closed before EOF
:circuit_openthe call was rejected by Arrea.CircuitBreaker
:rate_limitedthe call was rejected by Arrea.RateLimiter
:bulkhead_fullthe call was rejected by Arrea.Bulkhead
:unknownfallback for anything that does not match the taxonomy above

Summary

Functions

Classify a Unix exit code into a kind/0.

Build a %Trebejo.Error{} from an exit code, stderr and command line.

Render the error as a one-line, human-readable string.

Wrap a raw {:error, reason} from Arrea.Command (or any executor).

Types

kind()

@type kind() ::
  :not_found
  | :permission_denied
  | :invalid_args
  | :timeout
  | :signal
  | :exit_nonzero
  | :port_closed
  | :circuit_open
  | :rate_limited
  | :bulkhead_full
  | :unknown

t()

@type t() :: %Trebejo.Error{
  cmd: String.t() | nil,
  duration_ms: non_neg_integer() | nil,
  exit_status: non_neg_integer() | nil,
  kind: kind(),
  reason: term(),
  stderr: String.t() | nil
}

Functions

classify_exit(arg1)

@spec classify_exit(non_neg_integer()) :: kind()

Classify a Unix exit code into a kind/0.

from_exit(exit_status, stderr, cmd, opts \\ [])

@spec from_exit(non_neg_integer(), String.t(), String.t() | nil, keyword()) :: t()

Build a %Trebejo.Error{} from an exit code, stderr and command line.

Examples

iex> Trebejo.Error.from_exit(127, "", "nonexistent")
%Trebejo.Error{kind: :not_found, exit_status: 127, ...}

iex> Trebejo.Error.from_exit(126, "perm denied", "./bin")
%Trebejo.Error{kind: :permission_denied, exit_status: 126, ...}

message(err)

@spec message(t()) :: String.t()

Render the error as a one-line, human-readable string.

wrap(reason, opts)

@spec wrap(
  term(),
  keyword()
) :: t()

Wrap a raw {:error, reason} from Arrea.Command (or any executor).

Recognises :timeout and passes through Arrea-side reasons as-is.