pub struct DomainError {
pub output: ExitError,
pub source: Option<Box<dyn StdError + Send + Sync>>,
}
Expand description
Wrapper for errors that are not a Fault. It is used as the explicit_error::Error::Domain variant generic type.
It is highly recommended to implement the derive ExitError which generates the boilerplate for your domain errors. Otherwise you can implement the ToDomainError trait.
Error implements From<DomainError>
, use ?
and .into()
in functions and closures to convert to the Error::Domain variant.
§Examples
DomainError can be generated because of a predicate
use explicit_error_exit::{prelude::*, ExitError, Result, derive::ExitError};
use std::process::ExitCode;
#[derive(ExitError, Debug)]
enum MyError {
Foo,
}
impl From<&MyError> for ExitError {
fn from(value: &MyError) -> Self {
match value {
MyError::Foo => ExitError::new(
"Something went wrong because ..",
ExitCode::from(42)
),
}
}
}
fn business_logic() -> Result<()> {
if 1 < 2 {
Err(MyError::Foo)
.with_context("Usefull context to debug or monitor")?;
}
}
Or from a Result
#[derive(ExitError, Debug)]
enum MyError {
Foo,
}
fn business_logic() -> Result<()> {
Err(ErrorKind::Foo).map_err_or_fault(|e|
match e {
ErrorKind::Foo => Ok(MyError::Foo),
_ => Err(e)
}
)?;
}
Or an Option
Some(12).ok_or(ExitError::new("Something went wrong because ..", ExitCode::from(42)))?;
Fields§
§output: ExitError
§source: Option<Box<dyn StdError + Send + Sync>>
Trait Implementations§
Source§impl Debug for DomainError
impl Debug for DomainError
Source§impl Display for DomainError
impl Display for DomainError
Source§impl Domain for DomainError
impl Domain for DomainError
Source§impl Error for DomainError
impl Error for DomainError
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<DomainError> for Error<DomainError>
impl From<DomainError> for Error<DomainError>
Source§fn from(value: DomainError) -> Self
fn from(value: DomainError) -> Self
Converts to this type from the input type.
Source§impl From<DomainError> for MainError
impl From<DomainError> for MainError
Source§fn from(value: DomainError) -> Self
fn from(value: DomainError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for DomainError
impl !RefUnwindSafe for DomainError
impl Send for DomainError
impl Sync for DomainError
impl Unpin for DomainError
impl !UnwindSafe for DomainError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more