pub enum AppError {
Config {
message: String,
retryable: bool,
fatal: bool,
status: u16,
},
Filesystem {
path: Option<PathBuf>,
source: Error,
retryable: bool,
fatal: bool,
status: u16,
},
Network {
endpoint: String,
source: Option<Box<dyn StdError + Send + Sync>>,
retryable: bool,
fatal: bool,
status: u16,
},
Other {
message: String,
retryable: bool,
fatal: bool,
status: u16,
},
}Expand description
Example error enum that can be replaced by the define_errors! macro.
Variants§
Config
Configuration-related errors
Filesystem
Filesystem-related errors with optional path and source error
Network
Network-related errors
Fields
Other
Generic errors for anything not covered by specific variants
Implementations§
Source§impl AppError
Constructor methods for AppError
impl AppError
Constructor methods for AppError
Sourcepub fn filesystem(
path: impl Into<String>,
source: impl Into<Option<Error>>,
) -> Self
pub fn filesystem( path: impl Into<String>, source: impl Into<Option<Error>>, ) -> Self
Create a new Filesystem error
Sourcepub fn filesystem_with_source(path: impl Into<PathBuf>, source: Error) -> Self
pub fn filesystem_with_source(path: impl Into<PathBuf>, source: Error) -> Self
Create a filesystem error with specific source error
Sourcepub fn network(
endpoint: impl Into<String>,
source: impl Into<Option<Box<dyn StdError + Send + Sync>>>,
) -> Self
pub fn network( endpoint: impl Into<String>, source: impl Into<Option<Box<dyn StdError + Send + Sync>>>, ) -> Self
Create a new Network error
Sourcepub fn network_with_source(
endpoint: impl Into<String>,
source: Option<Box<dyn StdError + Send + Sync>>,
) -> Self
pub fn network_with_source( endpoint: impl Into<String>, source: Option<Box<dyn StdError + Send + Sync>>, ) -> Self
Create a network error with specific source error
Sourcepub fn with_retryable(self, retryable: bool) -> Self
pub fn with_retryable(self, retryable: bool) -> Self
Set whether this error is retryable
Sourcepub fn with_fatal(self, fatal: bool) -> Self
pub fn with_fatal(self, fatal: bool) -> Self
Set whether this error is fatal
Sourcepub fn with_status(self, status: u16) -> Self
pub fn with_status(self, status: u16) -> Self
Set the HTTP status code for this error
Sourcepub fn with_code(self, code: impl Into<String>) -> CodedError<Self>
pub fn with_code(self, code: impl Into<String>) -> CodedError<Self>
Add a code to this error
Source§impl AppError
impl AppError
Sourcepub async fn from_async_result<T, E>(result: Result<T, E>) -> Result<T, Self>
pub async fn from_async_result<T, E>(result: Result<T, E>) -> Result<T, Self>
Convert an async operation’s Result<T, E> (where E: std::error::Error + Send + Sync + 'static) into a
Result<T, AppError> by wrapping the error in
AppError::other(...), marked retryable and non-fatal.
Convenience for the common async fn -> Result<T, AppError>
pattern where the caller wants to flatten any
std::error::Error into an AppError shape.
Sourcepub async fn handle_async(&self) -> Result<(), Box<dyn StdError + Send + Sync>>
pub async fn handle_async(&self) -> Result<(), Box<dyn StdError + Send + Sync>>
Run the async hook on this error.
Equivalent to calling
<AppError as AsyncForgeError>::async_handle(&self).await;
AppError does not override the trait default, so this is a
no-op Ok(()). Exists for symmetry with the other
*_async builders on AppError.
Trait Implementations§
Source§impl AsyncForgeError for AppError
AppError participates in the AsyncForgeError surface so it can
be used wherever async-aware error metadata is required.
impl AsyncForgeError for AppError
AppError participates in the AsyncForgeError surface so it can
be used wherever async-aware error metadata is required.
All sync metadata methods (kind, caption, is_retryable,
is_fatal, status_code, exit_code, user_message,
dev_message) delegate to the existing
ForgeError implementation. The
async async_handle method uses
the trait’s default no-op implementation — AppError has no
default async behaviour beyond carrying its metadata.
§Breaking change from 0.9.x
0.9.x shipped a stub async_handle implementation here that
returned Ok(()) regardless of input but matched on AppError
variants as if it were doing something. The stub is removed in
1.0; the trait now provides a no-op default and AppError
inherits it.
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Source§fn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
Source§fn is_fatal(&self) -> bool
fn is_fatal(&self) -> bool
Source§fn status_code(&self) -> u16
fn status_code(&self) -> u16
Source§fn user_message(&self) -> String
fn user_message(&self) -> String
Source§fn dev_message(&self) -> String
fn dev_message(&self) -> String
Source§fn async_handle<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn async_handle<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
await step (logging, cleanup, telemetry) on error surfacing.
The default is a no-op; override if you need behaviour.Source§impl Error for AppError
impl Error for AppError
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()