kcode-codex-runtime-v2 0.1.2

Native dynamic-tool turns through the Codex app-server protocol
Documentation
use std::fmt::{Display, Formatter};

/// Stable classification for a runtime failure.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ErrorKind {
    /// The caller supplied an invalid request or response.
    InvalidInput,
    /// The Codex executable could not be started or contacted.
    Unavailable,
    /// Codex is not authenticated with ChatGPT.
    Authentication,
    /// The operation exceeded its deadline.
    Timeout,
    /// Codex returned an invalid or unsuccessful protocol message.
    Protocol,
    /// The caller stopped the turn.
    Cancelled,
}

/// One safe runtime error.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Error {
    kind: ErrorKind,
    message: String,
}

impl Error {
    pub(crate) fn new(kind: ErrorKind, message: impl Into<String>) -> Self {
        Self {
            kind,
            message: message.into(),
        }
    }

    /// Returns the stable error classification.
    pub const fn kind(&self) -> ErrorKind {
        self.kind
    }

    /// Returns the safe diagnostic message.
    pub fn message(&self) -> &str {
        &self.message
    }
}

impl Display for Error {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        formatter.write_str(&self.message)
    }
}

impl std::error::Error for Error {}

/// Result returned by this crate.
pub type Result<T> = std::result::Result<T, Error>;