aurelin_framework/cache/error.rs
1use std::time::Duration;
2
3use fred::error::Error as FredError;
4
5/// Failures returned by cache stores and typed cache operations.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 /// A value could not be encoded as the cache's JSON representation.
9 #[error("encode cache value for key [{key}]: {source}")]
10 Encode {
11 /// Cache key whose value could not be encoded.
12 key: String,
13 /// JSON encoding failure.
14 source: serde_json::Error,
15 },
16 /// Stored data did not decode as the requested Rust type.
17 #[error("decode cache value for key [{key}]: {source}")]
18 Decode {
19 /// Cache key containing invalid or mismatched data.
20 key: String,
21 /// JSON decoding failure.
22 source: serde_json::Error,
23 },
24 /// JSON null cannot be distinguished from Laravel's missing-value result.
25 #[error("cache value for key [{0}] cannot be null")]
26 NullValue(String),
27 /// An integer mutation encountered a value that was not a signed integer.
28 #[error("cache value for key [{key}] is not a signed integer")]
29 NotInteger {
30 /// Cache key containing the incompatible value.
31 key: String,
32 },
33 /// An integer mutation exceeded the range of an `i64`.
34 #[error("integer cache mutation overflowed for key [{0}]")]
35 IntegerOverflow(String),
36 /// Fred could not configure, connect to, or communicate with Redis.
37 #[error("redis cache operation failed: {0}")]
38 Redis(#[from] FredError),
39 /// A blocking lock acquisition reached its deadline.
40 #[error("timed out after {0:?} while acquiring cache lock")]
41 LockTimeout(Duration),
42}
43
44/// Failure from either the cache or a `remember` value resolver.
45#[derive(Debug, thiserror::Error)]
46pub enum RememberError<E> {
47 /// Reading or writing the cache failed.
48 #[error(transparent)]
49 Cache(#[from] Error),
50 /// The application value resolver failed.
51 #[error("cache value resolver failed: {0}")]
52 Resolve(E),
53}