#[derive(Masterror)]
{
// Attributes available to this derive:
#[error]
#[source]
#[from]
#[backtrace]
#[masterror]
#[provide]
}
Expand description
Re-export derive macros so users only depend on this crate.
The From<T> for AppError conversion generated by #[app_error(...)]
attaches the domain error as the source of the produced AppError,
keeping it downcastable and part of the error chain. Attaching requires
T: Send + Sync + 'static; use the no_source flag to opt out and drop
the domain error during conversion instead.
ยงExamples
use masterror::{AppCode, AppError, AppErrorKind, Error};
#[derive(Debug, Error)]
#[error("missing flag: {name}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
struct MissingFlag {
name: &'static str
}
let app: AppError = MissingFlag {
name: "feature"
}
.into();
assert!(matches!(app.kind, AppErrorKind::BadRequest));
assert!(app.downcast_ref::<MissingFlag>().is_some());
let code: AppCode = MissingFlag {
name: "other"
}
.into();
assert_eq!(code, AppCode::BadRequest);