use thiserror::Error;
#[cfg(feature = "serde")]
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum WireFormatError {
#[error("wire format major version mismatch: got {got}, expected {expected}")]
VersionMismatch {
got: u16,
expected: u16,
},
#[error("wire format has invalid magic header")]
InvalidMagic,
#[error("wire format kind mismatch: got {got}, expected {expected}")]
KindMismatch {
got: u8,
expected: u8,
},
#[error("wire format kind is reserved or unsupported: {kind}")]
UnsupportedKind {
kind: u8,
},
#[error("wire format flags are unsupported: {flags}")]
UnsupportedFlags {
flags: u8,
},
#[error("wire format type mismatch: got {got}, expected {expected}")]
TypeNameMismatch {
got: String,
expected: &'static str,
},
#[error("wire header is malformed: {0}")]
MalformedHeader(String),
#[error("wire body codec error: {0}")]
Codec(String),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum InsertError {
#[error("entry conflict — OnConflict::Reject configured and id is already cached")]
Conflict,
#[error("serialization failed during insert: {0}")]
Serialization(String),
#[error("backend write-through failed: {0}")]
BackendFailed(#[from] BackendError),
#[cfg(feature = "serde")]
#[error("wire-format error: {0}")]
WireFormat(#[from] WireFormatError),
}
#[cfg(feature = "serde")]
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum PunnuSnapshotError {
#[error("punnu snapshot wire-format error: {0}")]
WireFormat(#[from] WireFormatError),
#[error("punnu snapshot contains duplicate id")]
DuplicateId,
#[error("punnu snapshot contains {entries} entries but this pool allows at most {limit}")]
TooManyEntries {
entries: usize,
limit: usize,
},
#[error(
"punnu snapshot restore cannot run while {reserved} strict backend write(s) are in flight"
)]
BackendWriteInFlight {
reserved: usize,
},
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum FetchError {
#[error("backend operation failed during fetch: {0}")]
Backend(#[from] BackendError),
#[error("fetch serialization error: {0}")]
Serialization(String),
#[error("fetcher panicked while resolving {type_name}: {message}")]
FetcherPanic {
type_name: &'static str,
message: String,
},
#[error("fetcher returned a value whose id did not match the requested id for {type_name}")]
IdentityMismatch {
type_name: &'static str,
},
#[error("fetcher error: {0}")]
Custom(Box<dyn std::error::Error + Send + Sync>),
#[error("L1 insert failed during fetch: {0}")]
Insert(#[from] InsertError),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum BackendError {
#[error("backend reports entry not found")]
NotFound,
#[error("backend serialization error: {0}")]
Serialization(String),
#[cfg(feature = "serde")]
#[error("backend wire-format error: {0}")]
WireFormat(#[from] WireFormatError),
#[error("backend network error: {0}")]
Network(String),
#[error("backend error: {0}")]
Other(Box<dyn std::error::Error + Send + Sync>),
}
#[cfg(feature = "serde")]
impl From<serde_json::Error> for BackendError {
fn from(err: serde_json::Error) -> Self {
Self::Serialization(err.to_string())
}
}