tower_http_cache/error.rs
1use thiserror::Error;
2
3/// Errors that can occur while interacting with a cache backend.
4///
5/// Marked `#[non_exhaustive]` as of 0.6.0: match arms must include a `_`
6/// fallback, and future variants are then additive rather than breaking.
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum CacheError {
10 #[error("backend error: {0}")]
11 Backend(String),
12
13 /// The backend does not implement the requested operation.
14 ///
15 /// Returned by the shared backends for the tag-index operations
16 /// (`get_keys_by_tag`, `list_tags`, and therefore `invalidate_by_tag`),
17 /// which they cannot serve. Reporting it is deliberate: up to 0.5.x they
18 /// inherited the trait defaults and answered `Ok(vec![])` / `Ok(0)`, so a
19 /// caller could not tell "nothing carried that tag" from "this backend
20 /// cannot do tags at all".
21 #[error("unsupported by this backend: {0}")]
22 Unsupported(String),
23
24 #[cfg(feature = "redis-backend")]
25 #[error(transparent)]
26 Redis(#[from] redis::RedisError),
27}
28
29impl CacheError {
30 /// Reports whether this is [`CacheError::Unsupported`].
31 pub fn is_unsupported(&self) -> bool {
32 matches!(self, CacheError::Unsupported(_))
33 }
34}