Skip to main content

datum_cdc/
error.rs

1use thiserror::Error;
2
3/// Result alias used by `datum-cdc`.
4pub type CdcResult<T> = Result<T, CdcError>;
5
6/// Error type for PostgreSQL CDC source construction, administration, parsing,
7/// checkpointing, and carrier failures.
8#[derive(Debug, Error)]
9pub enum CdcError {
10    #[error("configuration error: {0}")]
11    Config(String),
12    #[error("PostgreSQL control-plane error: {0}")]
13    Postgres(#[from] tokio_postgres::Error),
14    #[error("PostgreSQL replication error: {0}")]
15    Replication(String),
16    #[error("pgoutput parse error: {0}")]
17    Parse(String),
18    #[error("replication slot error: {0}")]
19    Slot(String),
20    #[error("checkpoint error: {0}")]
21    Checkpoint(String),
22    #[error("CDC source channel closed")]
23    ChannelClosed,
24    #[error("Datum stream error: {0}")]
25    Stream(String),
26    #[error("I/O error: {0}")]
27    Io(#[from] std::io::Error),
28    #[error("runtime error: {0}")]
29    Runtime(String),
30}
31
32impl From<pgwire_replication::PgWireError> for CdcError {
33    fn from(value: pgwire_replication::PgWireError) -> Self {
34        Self::Replication(value.to_string())
35    }
36}
37
38impl From<serde_json::Error> for CdcError {
39    fn from(value: serde_json::Error) -> Self {
40        Self::Checkpoint(value.to_string())
41    }
42}
43
44impl From<datum::StreamError> for CdcError {
45    fn from(value: datum::StreamError) -> Self {
46        Self::Stream(value.to_string())
47    }
48}