Skip to main content

codex_app_server_client/
error.rs

1/// Errors returned by [`crate::CodexAppServerClient`].
2///
3/// `#[non_exhaustive]` because this crate expects to grow new failure modes
4/// over time (see the README's schema-regeneration workflow) - matching
5/// exhaustively on this enum today would make every future variant addition
6/// a breaking change for downstream crates.
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    #[error("failed to spawn `{command}`: {source}")]
11    Spawn {
12        command: String,
13        #[source]
14        source: std::io::Error,
15    },
16
17    #[error("transport I/O error: {0}")]
18    Io(#[from] std::io::Error),
19
20    #[error("failed to (de)serialize a protocol message: {0}")]
21    Serde(#[from] serde_json::Error),
22
23    #[error("the app-server connection closed before a response arrived")]
24    TransportClosed,
25
26    #[error("no response after {after:?}")]
27    Timeout { after: std::time::Duration },
28
29    #[error("app-server returned a JSON-RPC error (code {code}): {message}")]
30    Rpc {
31        code: i64,
32        message: String,
33        data: Option<serde_json::Value>,
34    },
35}
36
37pub type Result<T> = std::result::Result<T, Error>;