Skip to main content

Module error

Module error 

Source
Available on crate feature terminal only.
Expand description

Command failure reporting to stdout.

ErrorReport renders a failure, with its source chain and backtrace, as text or JSON. A binary acting as a machine contract also gives the failures a caller is expected to act on a stable code: it declares its own ErrorCode vocabulary, raises a CodedError anywhere in the chain, and evaluates its result with ErrorReport::eval_coded, which prints the code as code beside the message. The message stays for humans and may be reworded at any time; the code is the contract.

A command that ran to its end but did not fully succeed prints its result, then returns a PartialOutcome: the process exits with its status, 3 or above, and prints nothing more. A command line the grammar refuses exits 2, its failure object coded usage-invalid under --json (see crate::clap::parse).

A command acting on several items lists the failure of each single item as an ItemError in its result’s errors, then exits 3.

Structs§

CodedError
A failure carrying an ErrorCode, anywhere in an error chain.
ErrorReport
Wraps an anyhow::Error to render it, with its source chain, backtrace and code, as text or JSON.
ItemError
The error of one item a command could not list or act on.
ItemErrors
The item errors a command prints last, one aligned Error: line each.
PartialOutcome
The outcome of a command that printed its result but did not fully succeed, such as a check with a failed backend or a refusal from a server.

Enums§

CommonCode
The codes pimalaya-cli raises itself, beside every binary’s own vocabulary.
NoErrorCode
The empty vocabulary of a binary whose failures carry no code.

Constants§

EXIT_FAILURE
The exit status of a failed command, which printed the failure object.
EXIT_PARTIAL
The exit status of a command that ran to its end and printed its result, whose outcome is not a full success. A command may document higher statuses for other such outcomes.
EXIT_USAGE
The exit status of a command line the grammar refuses, clap’s own.

Traits§

ErrorCode
A binary’s vocabulary of stable failure codes.

Functions§

code_of
The code of the outermost CodedError in the chain, if any.
failure_status
The status a failure exits with: EXIT_USAGE when its chain is coded CommonCode::UsageInvalid, a command line refused after clap parsed it, EXIT_FAILURE otherwise.
partial_outcome_of
The PartialOutcome in the chain, if any.
usage_error
The failure of a command line the grammar refuses, coded CommonCode::UsageInvalid, with clap’s message stripped of its error: prefix and of its styles.
with_code
err as the report reads it, the code code finds in its chain carried by an innermost CodedError.