//! Errors and error specific types for universal use /// Custom Result /// A custom datatype that wraps the error variant into a report, allowing /// error_stack::Report specific extendability /// /// Effectively, equivalent to `Result>` /// pub type CustomResult = error_stack::Result; macro_rules! impl_error_display { ($st: ident, $arg: tt) => { impl std::fmt::Display for $st { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fmt.write_str(&format!( "{{ error_type: {:?}, error_description: {} }}", self, $arg )) } } }; } macro_rules! impl_error_type { ($name: ident, $arg: tt) => { #[doc = ""] #[doc = stringify!(Error variant $name)] #[doc = stringify!(Custom error variant for $arg)] #[doc = ""] #[derive(Debug)] pub struct $name; impl_error_display!($name, $arg); impl std::error::Error for $name {} }; } impl_error_type!(ParsingError, "Parsing error"); /// Validation errors. #[allow(missing_docs)] // Only to prevent warnings about struct fields not being documented #[derive(Debug, thiserror::Error)] pub enum ValidationError { /// The provided input is missing a required field. #[error("Missing required field: {field_name}")] MissingRequiredField { field_name: String }, /// An incorrect value was provided for the field specified by `field_name`. #[error("Incorrect value provided for field: {field_name}")] IncorrectValueProvided { field_name: &'static str }, /// An invalid input was provided. #[error("{message}")] InvalidValue { message: String }, }