use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("failed to parse thread event line: {0}")]
EventParse(#[from] serde_json::Error),
#[error("codex exec failed: {0}")]
Exec(String),
#[error("thread run error: {0}")]
ThreadRun(String),
#[error("codex install failed: {0}")]
Install(String),
#[error("codex auth failed: {0}")]
Auth(String),
#[error("rate limited")]
RateLimit,
#[error("invalid continuation: {0}")]
InvalidContinuation(String),
#[error("BYOK is not supported for Codex SDK")]
InvalidByok,
#[error("invalid messages: {0}")]
InvalidMessages(String),
#[error("unsupported response format")]
UnsupportedResponseFormat,
#[error("spawn error: {0}")]
Spawn(String),
#[error("IO error: {0}")]
Io(String),
#[error("JSON error: {0}")]
Json(String),
#[error("stderr: {0}")]
Stderr(String),
#[error("no output from subprocess")]
NoOutput,
#[error("Codex SDK does not support tools")]
ToolsNotAllowed,
#[error("Codex SDK is not enabled")]
NotEnabled,
#[error("image fetch failed: {0}")]
ImageFetch(String),
}
impl objectiveai_sdk::error::StatusError for Error {
fn status(&self) -> u16 {
match self {
Self::RateLimit => 429,
Self::InvalidContinuation(_)
| Self::InvalidByok
| Self::InvalidMessages(_)
| Self::UnsupportedResponseFormat
| Self::ToolsNotAllowed
| Self::NotEnabled => 400,
Self::EventParse(_)
| Self::Exec(_)
| Self::ThreadRun(_)
| Self::Install(_)
| Self::Auth(_)
| Self::Spawn(_)
| Self::Io(_)
| Self::Json(_)
| Self::Stderr(_)
| Self::NoOutput
| Self::ImageFetch(_) => 500,
}
}
fn message(&self) -> Option<serde_json::Value> {
Some(serde_json::Value::String(self.to_string()))
}
}