pub struct Error { /* private fields */ }Expand description
A common error type for all Tango operations, which supports metadata and easy chaining of errors.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind<'_>) -> Self
pub fn new(kind: ErrorKind<'_>) -> Self
Create a new error of the given kind, this will grab the origin of the error from the caller’s location. A default description is written depending on it by default, you can append or replace this description later.
Sourcepub fn kind(&self) -> ErrorKind<'_>
pub fn kind(&self) -> ErrorKind<'_>
Get the kind of error, returning the raw reason if not categorized.
Sourcepub fn set_kind(&mut self, kind: ErrorKind<'_>)
pub fn set_kind(&mut self, kind: ErrorKind<'_>)
Change the kind of this error, this also ensures that the associated reason corresponds to the new error kind. If the description is empty at this point, the description is overridden with a default description.
Sourcepub fn with_kind(self, kind: ErrorKind<'_>) -> Self
pub fn with_kind(self, kind: ErrorKind<'_>) -> Self
Change the kind of this error, and return itself.
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Return the description of the error.
Sourcepub fn append_description(&mut self, additional: impl Display)
pub fn append_description(&mut self, additional: impl Display)
Append the given additional description to the error’s description, if the description is currently empty, then this replaces the previous description. If a description already exists, it appends the description on a new line.
Sourcepub fn set_description(&mut self, description: impl Into<Cow<'static, str>>)
pub fn set_description(&mut self, description: impl Into<Cow<'static, str>>)
Overwrite any existing description with the given one.
Sourcepub fn with_append_description(self, additional: impl Display) -> Self
pub fn with_append_description(self, additional: impl Display) -> Self
Same as Self::append_description, and return itself.
Sourcepub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
pub fn with_description(self, description: impl Into<Cow<'static, str>>) -> Self
Overwrite any existing description with the given one, and return itself.
Sourcepub fn severity(&self) -> ErrorSeverity
pub fn severity(&self) -> ErrorSeverity
Return the severity of this error.
Sourcepub fn set_severity(&mut self, severity: ErrorSeverity)
pub fn set_severity(&mut self, severity: ErrorSeverity)
Set the severity of the error.
Sourcepub fn with_severity(self, severity: ErrorSeverity) -> Self
pub fn with_severity(self, severity: ErrorSeverity) -> Self
Set the severity of the error, and return itself.
Sourcepub fn origin(&self) -> &str
pub fn origin(&self) -> &str
Return the origin of this error, set by default to the caller’s code location.
Sourcepub fn append_origin(&mut self, additional: impl Display)
pub fn append_origin(&mut self, additional: impl Display)
Append the given additional origin to the existing origin, in order to add details, a space is added before insertion. If the origin has been replaced and is empty, then no space is added.
Sourcepub fn set_origin(&mut self, origin: impl Into<Cow<'static, str>>)
pub fn set_origin(&mut self, origin: impl Into<Cow<'static, str>>)
Overwrite any existing origin with the given one.
Sourcepub fn with_append_origin(self, additional: impl Display) -> Self
pub fn with_append_origin(self, additional: impl Display) -> Self
Same as Self::append_origin, and return itself.
Sourcepub fn with_origin(self, origin: impl Into<Cow<'static, str>>) -> Self
pub fn with_origin(self, origin: impl Into<Cow<'static, str>>) -> Self
Overwrite any existing origin with the given one, and return itself.
Sourcepub fn set_origin_from_caller(&mut self)
pub fn set_origin_from_caller(&mut self)
Overwrite the existing origin with the current location of the caller.
Sourcepub fn with_origin_from_caller(self) -> Self
pub fn with_origin_from_caller(self) -> Self
Overwrite the existing origin with the current location of the caller, and return itself.
Sourcepub fn parent(&self) -> Option<&Error>
pub fn parent(&self) -> Option<&Error>
If the source of this error is a parent Tango error, returns a shared ref to it.
To get a more generic source for this error, use the standard
error::Error::source method.
Sourcepub fn set_parent(&mut self, parent: Error)
pub fn set_parent(&mut self, parent: Error)
Set the parent source of this error.
Sourcepub fn with_parent(self, parent: Error) -> Self
pub fn with_parent(self, parent: Error) -> Self
Set the parent source of this error and return itself.
Trait Implementations§
Source§impl Display for Error
The whole chain of this error and its parents, on a single line, each error giving its
reason and its description, escaped so that a description of several lines stays on
that line: this is what a log line carries, see {:#} for what a person reads.
impl Display for Error
The whole chain of this error and its parents, on a single line, each error giving its
reason and its description, escaped so that a description of several lines stays on
that line: this is what a log line carries, see {:#} for what a person reads.
The alternate form gives an error per block, the origin of each of them along with it: a code location is noise in a log line, and the first thing wanted when debugging.
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()