use monoloop_contracts::{ConnectorError, ConnectorErrorKind};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CodexConnectorError {
pub kind: ConnectorErrorKind,
pub message: String,
}
impl CodexConnectorError {
pub fn configuration(msg: impl Into<String>) -> Self {
Self {
kind: ConnectorErrorKind::ConfigurationInvalid,
message: msg.into(),
}
}
pub fn connection(msg: impl Into<String>) -> Self {
Self {
kind: ConnectorErrorKind::ConnectionFailed,
message: msg.into(),
}
}
pub fn protocol(msg: impl Into<String>) -> Self {
Self {
kind: ConnectorErrorKind::ProtocolFailed,
message: msg.into(),
}
}
pub fn deadline(msg: impl Into<String>) -> Self {
Self {
kind: ConnectorErrorKind::DeadlineExceeded,
message: msg.into(),
}
}
pub fn session(msg: impl Into<String>) -> Self {
Self {
kind: ConnectorErrorKind::SessionFailed,
message: msg.into(),
}
}
pub fn cancelled() -> Self {
Self {
kind: ConnectorErrorKind::Cancelled,
message: "codex session cancelled".into(),
}
}
pub fn into_connector_error(self) -> ConnectorError {
ConnectorError::new(self.kind, self.message)
}
}
impl From<CodexConnectorError> for ConnectorError {
fn from(e: CodexConnectorError) -> Self {
e.into_connector_error()
}
}
impl std::fmt::Display for CodexConnectorError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}: {}", self.kind, self.message)
}
}
impl std::error::Error for CodexConnectorError {}