Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.2 KB
Raw Blame
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error(transparent)]
    Store(#[from] assignment_coordination::error::Error),

    #[error("key not found: {0}")]
    NotFound(String),

    #[error("handoff failed for {topic}/{partition}: {reason}")]
    HandoffFailed {
        topic: String,
        partition: u32,
        reason: String,
    },
}

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Self::Store(e.into())
    }
}

impl From<etcd_client::Error> for Error {
    fn from(e: etcd_client::Error) -> Self {
        Self::Store(e.into())
    }
}

impl From<Error> for assignment_coordination::error::Error {
    fn from(e: Error) -> Self {
        match e {
            Error::Store(inner) => inner,
            other => Self::InvalidState(other.to_string()),
        }
    }
}

impl Error {
    pub fn invalid_state(msg: impl Into<String>) -> Self {
        Self::Store(assignment_coordination::error::Error::InvalidState(
            msg.into(),
        ))
    }

    pub fn leadership_lost() -> Self {
        Self::Store(assignment_coordination::error::Error::LeadershipLost)
    }
}

pub type Result<T> = std::result::Result<T, Error>;