Skip to main content

kape_postgres/
error.rs

1use kape::KapeError;
2
3/// A `PostgreSQL` adapter failure.
4#[derive(Debug, thiserror::Error)]
5pub enum PostgresBackendError {
6    /// Key or value encoding failed.
7    #[error("PostgreSQL codec failed: {0}")]
8    Codec(#[source] Box<dyn std::error::Error + Send + Sync>),
9    /// `PostgreSQL` operation failed.
10    #[error("PostgreSQL operation failed: {0}")]
11    Sqlx(#[from] sqlx::Error),
12    /// The application host clock is earlier than the Unix epoch.
13    #[error("application system clock is before the Unix epoch")]
14    SystemClockBeforeUnixEpoch(#[source] std::time::SystemTimeError),
15    /// The application host's Unix millisecond timestamp exceeds `i64`.
16    #[error("application Unix millisecond timestamp exceeds i64 range")]
17    TimestampOverflow,
18    /// A finite TTL cannot be represented as an absolute Unix millisecond timestamp.
19    #[error("TTL exceeds PostgreSQL millisecond range")]
20    TtlOverflow,
21    /// A table name was empty, unsafe, or contained more than schema and table.
22    #[error("invalid table name '{0}'")]
23    InvalidTableName(String),
24}
25
26impl PostgresBackendError {
27    /// Erases a codec-specific error at the adapter boundary.
28    pub fn codec<E>(error: E) -> Self
29    where
30        E: std::error::Error + Send + Sync + 'static,
31    {
32        Self::Codec(Box::new(error))
33    }
34}
35
36impl From<PostgresBackendError> for KapeError {
37    fn from(error: PostgresBackendError) -> Self {
38        Self::backend(error)
39    }
40}