apiari_codex_sdk/error.rs
1//! SDK error types.
2//!
3//! Provides [`SdkError`], the unified error type for all operations in this crate.
4
5use std::io;
6
7/// Unified error type for all SDK operations.
8#[derive(Debug, thiserror::Error)]
9pub enum SdkError {
10 /// Failed to spawn the `codex` subprocess.
11 #[error("failed to spawn codex process: {0}")]
12 ProcessSpawn(#[source] io::Error),
13
14 /// The `codex` process exited unexpectedly.
15 #[error("codex process died (exit code: {exit_code:?}, stderr: {stderr})")]
16 ProcessDied {
17 /// Exit code, if available.
18 exit_code: Option<i32>,
19 /// Captured stderr output.
20 stderr: String,
21 },
22
23 /// A line from stdout was not valid JSON.
24 #[error("invalid JSON from codex stdout: {message}")]
25 InvalidJson {
26 /// Human-readable description of the parse failure.
27 message: String,
28 /// The raw line that failed to parse.
29 line: String,
30 /// The underlying serde error.
31 #[source]
32 source: serde_json::Error,
33 },
34
35 /// The JSON was valid but did not match any expected protocol shape.
36 #[error("protocol error: {0}")]
37 ProtocolError(String),
38
39 /// An operation exceeded its deadline.
40 #[error("operation timed out after {0:?}")]
41 Timeout(std::time::Duration),
42
43 /// Generic I/O error (stdout read, etc.).
44 #[error("I/O error: {0}")]
45 Io(#[from] io::Error),
46
47 /// The execution has already finished.
48 #[error("execution is not running")]
49 NotRunning,
50}
51
52/// Convenience alias used throughout the crate.
53pub type Result<T> = std::result::Result<T, SdkError>;