Skip to main content

coil_cache/
error.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum CacheModelError {
6    EmptyField { field: &'static str },
7    InvalidToken { field: &'static str, value: String },
8    PublicScopeCannotVaryByUser,
9    PublicScopeCannotVaryBySession,
10    UncacheableApplicationScope,
11    MissingHttpFreshness,
12    NoStoreCannotDefineFreshness,
13    ZeroDuration { field: &'static str },
14    UnknownInflightFill { key: String },
15}
16
17impl fmt::Display for CacheModelError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Self::EmptyField { field } => write!(f, "`{field}` cannot be empty"),
21            Self::InvalidToken { field, value } => {
22                write!(f, "`{field}` contains an invalid token `{value}`")
23            }
24            Self::PublicScopeCannotVaryByUser => {
25                f.write_str("public cache scopes cannot vary by user")
26            }
27            Self::PublicScopeCannotVaryBySession => {
28                f.write_str("public cache scopes cannot vary by session")
29            }
30            Self::UncacheableApplicationScope => {
31                f.write_str("application cache policy cannot use a no-store scope")
32            }
33            Self::MissingHttpFreshness => {
34                f.write_str("cacheable HTTP responses must define a freshness policy")
35            }
36            Self::NoStoreCannotDefineFreshness => {
37                f.write_str("no-store HTTP responses cannot define freshness")
38            }
39            Self::ZeroDuration { field } => write!(f, "`{field}` must be greater than zero"),
40            Self::UnknownInflightFill { key } => {
41                write!(f, "cache fill for `{key}` is not currently in progress")
42            }
43        }
44    }
45}
46
47impl Error for CacheModelError {}