Skip to main content

Error

Struct Error 

Source
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

Source

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());
Source

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");
Source

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());
Source

pub fn is_source<T>(&self) -> bool
where 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>());
Source

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 Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Enrichable for Error

Source§

fn add_enrichment(&mut self, entry: EnrichmentEntry)

Adds enrichment information to the error. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl ErrorExt for Error

Source§

fn message(&self) -> String

Returns the formatted error message without backtrace. Read more
Source§

fn backtrace(&self) -> &Backtrace

Returns a reference to the captured backtrace. Read more
Source§

fn has_backtrace(&self) -> bool

Returns true if the error has a captured backtrace. Read more
Source§

fn find_source<T>(&self) -> Option<&T>
where T: Error + 'static,

Finds the first source error of the specified type in the error chain. Read more
Source§

fn find_source_with<T>(&self, search: impl Fn(&T) -> bool) -> Option<&T>
where T: Error + 'static,

Finds the first source error of the specified type that matches the given predicate. Read more
Source§

impl From<Error> for SizeError

Source§

fn from(error: Error) -> SizeError

Converts to this type from the input type.
Source§

impl From<Infallible> for Error

Source§

fn from(_: Infallible) -> Error

Converts to this type from the input type.
Source§

impl From<SizeError> for Error

Source§

fn from(err: SizeError) -> Error

Converts to this type from the input type.
Source§

impl Recovery for Error

Source§

fn recovery(&self) -> RecoveryInfo

Returns recovery information for this instance. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> EnrichableExt for T
where T: Enrichable,

Source§

fn enrich(self, msg: impl Into<Cow<'static, str>>) -> Self
where Self: Sized,

Adds enrichment information to the error. Read more
Source§

fn enrich_with<F, R>(self, f: F) -> Self
where F: FnOnce() -> R, R: Into<Cow<'static, str>>, Self: Sized,

Adds lazily evaluated enrichment information to the error. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more