use thiserror::Error;
pub type CdcResult<T> = Result<T, CdcError>;
#[derive(Debug, Error)]
pub enum CdcError {
#[error("configuration error: {0}")]
Config(String),
#[error("PostgreSQL control-plane error: {0}")]
Postgres(#[from] tokio_postgres::Error),
#[error("PostgreSQL replication error: {0}")]
Replication(String),
#[error("pgoutput parse error: {0}")]
Parse(String),
#[error("replication slot error: {0}")]
Slot(String),
#[error("checkpoint error: {0}")]
Checkpoint(String),
#[error("CDC source channel closed")]
ChannelClosed,
#[error("Datum stream error: {0}")]
Stream(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("runtime error: {0}")]
Runtime(String),
}
impl From<pgwire_replication::PgWireError> for CdcError {
fn from(value: pgwire_replication::PgWireError) -> Self {
Self::Replication(value.to_string())
}
}
impl From<serde_json::Error> for CdcError {
fn from(value: serde_json::Error) -> Self {
Self::Checkpoint(value.to_string())
}
}
impl From<datum::StreamError> for CdcError {
fn from(value: datum::StreamError) -> Self {
Self::Stream(value.to_string())
}
}