pub struct Failure { /* private fields */ }Expand description
A single machine-readable failure.
Construct through the category helpers rather than the struct literal, so the retry mark stays consistent with the category.
Implementations§
Source§impl Failure
impl Failure
Sourcepub fn new(
category: Category,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn new( category: Category, code: &'static str, message: impl Into<String>, ) -> Self
Builds a failure in the given category.
code is a stable identifier callers may branch on; it never changes
meaning between releases. message is human prose and is never used as
an identifier.
Sourcepub fn with_detail(self, name: &'static str, value: impl Into<String>) -> Self
pub fn with_detail(self, name: &'static str, value: impl Into<String>) -> Self
Records one measured value under the name a catalogue substitutes it by.
This is how a failure keeps its measurements without wording a sentence around them: the source supplies the value, and the catalogue of the reader’s language supplies the words.
Sourcepub fn with_hint(self, hint: impl Into<String>) -> Self
pub fn with_hint(self, hint: impl Into<String>) -> Self
Attaches a concrete next action for the caller.
Sourcepub const fn with_retryable(self, retryable: bool) -> Self
pub const fn with_retryable(self, retryable: bool) -> Self
Overrides the category’s default retry mark.
Used for server conditions, where whether repeating helps depends on the condition rather than on the category.
Sourcepub fn with_cause(self, cause: impl Into<String>) -> Self
pub fn with_cause(self, cause: impl Into<String>) -> Self
Appends one link to the cause chain, outermost first.
Sourcepub fn with_extra_condition(self, condition: impl Into<String>) -> Self
pub fn with_extra_condition(self, condition: impl Into<String>) -> Self
Records a server condition beyond the first one.
The server may report several conditions for one statement; reporting only the first hides the rest from the caller.
Sourcepub fn extra_conditions(&self) -> &[String]
pub fn extra_conditions(&self) -> &[String]
Server conditions beyond the first.
Sourcepub fn details(&self) -> &[(&'static str, String)]
pub fn details(&self) -> &[(&'static str, String)]
The measured values this failure carries, each under its name.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether repeating the same call may succeed without changing the input.
Sourcepub const fn exit_number(&self) -> ExitNumber
pub const fn exit_number(&self) -> ExitNumber
The exit number this failure produces.
Source§impl Failure
Constructors grouped by category, so the retry mark is never set by hand.
impl Failure
Constructors grouped by category, so the retry mark is never set by hand.
Sourcepub fn usage(code: &'static str, message: impl Into<String>) -> Self
pub fn usage(code: &'static str, message: impl Into<String>) -> Self
The caller’s input to this tool is wrong.
Sourcepub fn validation(code: &'static str, message: impl Into<String>) -> Self
pub fn validation(code: &'static str, message: impl Into<String>) -> Self
Analysis refused the statement before it was sent.
Sourcepub fn config(code: &'static str, message: impl Into<String>) -> Self
pub fn config(code: &'static str, message: impl Into<String>) -> Self
A profile or setting is missing or invalid.
Sourcepub fn network(code: &'static str, message: impl Into<String>) -> Self
pub fn network(code: &'static str, message: impl Into<String>) -> Self
The server could not be reached.
Sourcepub fn authentication(code: &'static str, message: impl Into<String>) -> Self
pub fn authentication(code: &'static str, message: impl Into<String>) -> Self
The credential was refused.
Sourcepub fn permission(code: &'static str, message: impl Into<String>) -> Self
pub fn permission(code: &'static str, message: impl Into<String>) -> Self
The credential may not do what was asked.
Sourcepub fn absence(code: &'static str, message: impl Into<String>) -> Self
pub fn absence(code: &'static str, message: impl Into<String>) -> Self
The requested object does not exist.
Sourcepub fn conflict(code: &'static str, message: impl Into<String>) -> Self
pub fn conflict(code: &'static str, message: impl Into<String>) -> Self
The change hit a lock, a deadlock or a constraint.
Sourcepub fn timeout(code: &'static str, message: impl Into<String>) -> Self
pub fn timeout(code: &'static str, message: impl Into<String>) -> Self
Some phase exceeded its time budget.
Sourcepub fn server(code: &'static str, message: impl Into<String>) -> Self
pub fn server(code: &'static str, message: impl Into<String>) -> Self
The server returned an error of its own.
Sourcepub fn limit(code: &'static str, message: impl Into<String>) -> Self
pub fn limit(code: &'static str, message: impl Into<String>) -> Self
A size, row or packet ceiling was reached.
Sourcepub fn interrupted(code: &'static str, message: impl Into<String>) -> Self
pub fn interrupted(code: &'static str, message: impl Into<String>) -> Self
The work was cancelled from outside.
Trait Implementations§
Source§impl Error for Failure
impl Error for Failure
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()