pub struct Error { /* private fields */ }Expand description
Failure to produce an operation’s requested output.
Every value contains a registered error diagnostic. An underlying I/O or
library error remains available through std::error::Error::source.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(info: &'static DiagnosticInfo, message: impl Into<String>) -> Self
pub fn new(info: &'static DiagnosticInfo, message: impl Into<String>) -> Self
Construct a failure from a registered code carrying a category.
A code that ends an operation must declare a category, because the
category is what a binding and an exit status project the failure onto.
A code that does not is a registry defect: the finding keeps its own
code so its identity is not lost, and a REQUEST.DIAGNOSTIC.MISSING_CATEGORY
note records the defect. A debug build asserts instead, so the defect
surfaces in tests rather than in a released binding.
Sourcepub fn with_diagnostic(self, diagnostic: Diagnostic) -> Self
pub fn with_diagnostic(self, diagnostic: Diagnostic) -> Self
Add a diagnostic emitted before or while the operation failed.
Sourcepub fn with_diagnostics(
self,
diagnostics: impl IntoIterator<Item = Diagnostic>,
) -> Self
pub fn with_diagnostics( self, diagnostics: impl IntoIterator<Item = Diagnostic>, ) -> Self
Add diagnostics without changing their order.
Sourcepub fn with_cause(self, cause: impl Error + Send + Sync + 'static) -> Self
pub fn with_cause(self, cause: impl Error + Send + Sync + 'static) -> Self
Retain the implementation error that caused this operation failure.
Sourcepub fn with_source(self, source: Source) -> Self
pub fn with_source(self, source: Source) -> Self
Retain the shared input owner needed to interpret diagnostic spans.
pub fn diagnostics(&self) -> &[Diagnostic]
Sourcepub fn info(&self) -> Option<&'static DiagnosticInfo>
pub fn info(&self) -> Option<&'static DiagnosticInfo>
The registered entry of the diagnostic that ended the operation, when the failure was built from one.
Sourcepub fn category(&self) -> ErrorCategory
pub fn category(&self) -> ErrorCategory
Coarse projection from the first registered error diagnostic.
pub const fn retained_source(&self) -> Option<&Source>
pub fn into_diagnostics(self) -> Vec<Diagnostic>
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()