pub struct Error { /* private fields */ }Expand description
An error from a cache operation.
Wraps any underlying error from a cache implementation while preserving the ability to extract the original typed error.
§For CacheTier implementers
Wrap your storage-specific errors using from_source:
impl CacheTier<K, V> for RedisCache {
async fn get(&self, key: &K) -> Result<Option<CacheEntry<V>>, Error> {
self.client.get(key).await.map_err(Error::from_source)
}
}§For Consumers
Extract the underlying error using source_as or
find_source:
match cache.get(&key).await {
Err(e) if e.is_source::<redis::RedisError>() => {
let redis_err = e.source_as::<redis::RedisError>().unwrap();
// Handle Redis-specific error
}
Err(e) => // Handle generic error
Ok(v) => // Success
}Implementations§
Source§impl Error
impl Error
Sourcepub fn from_source(cause: impl Into<Box<dyn Error + Send + Sync>>) -> Error
pub fn from_source(cause: impl Into<Box<dyn Error + Send + Sync>>) -> Error
Creates a new error wrapping a source error.
This preserves the original error type for later extraction via
source_as.
§Examples
use cachet_tier::Error;
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file missing");
let error = Error::from_source(io_err);
// Later, extract the original error
assert!(error.source_as::<std::io::Error>().is_some());Sourcepub fn from_message(message: impl Into<String>) -> Error
pub fn from_message(message: impl Into<String>) -> Error
Creates a new error from a message string.
Use from_source instead when wrapping an existing error.
§Examples
use cachet_tier::Error;
let error = Error::from_message("operation failed");Sourcepub fn with_recovery(self, recovery_info: RecoveryInfo) -> Error
pub fn with_recovery(self, recovery_info: RecoveryInfo) -> Error
Attaches recovery information to this error.
This is for informational purposes and does not affect error handling logic. It can be used by monitoring or debugging tools to provide hints on how to recover from the error.
§Examples
use cachet_tier::Error;
use recoverable::RecoveryInfo;
let error = Error::from_message("temporary failure").with_recovery(RecoveryInfo::retry());Sourcepub fn is_source<T>(&self) -> boolwhere
T: Error + 'static,
pub fn is_source<T>(&self) -> boolwhere
T: Error + 'static,
Returns true if the source error is of type T.
§Examples
use cachet_tier::Error;
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "not found");
let error = Error::from_source(io_err);
assert!(error.is_source::<std::io::Error>());
assert!(!error.is_source::<std::fmt::Error>());Sourcepub fn source_as<T>(&self) -> Option<&T>where
T: Error + 'static,
pub fn source_as<T>(&self) -> Option<&T>where
T: Error + 'static,
Returns the source error as type T if it matches.
This checks the immediate source. For nested errors, use
find_source from the ErrorExt trait.
§Examples
use cachet_tier::Error;
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "not found");
let error = Error::from_source(io_err);
if let Some(io_err) = error.source_as::<std::io::Error>() {
assert_eq!(io_err.kind(), std::io::ErrorKind::NotFound);
}Trait Implementations§
Source§impl Enrichable for Error
impl Enrichable for Error
Source§fn add_enrichment(&mut self, entry: EnrichmentEntry)
fn add_enrichment(&mut self, entry: EnrichmentEntry)
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()