Skip to main content

objectiveai_sdk/daemon/
error.rs

1//! The ONE error type for every [`super::Client`] surface — the
2//! listeners' former per-module enums folded together with the plain
3//! HTTP calls' status mapping.
4
5/// Any failure across the daemon client's surfaces: opening an SSE
6/// stream, a plain HTTP call, or decoding what came back.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// The request could not be turned into an SSE stream (builder
10    /// rejected it).
11    #[error("connect daemon sse: {0}")]
12    Connect(#[from] reqwest_eventsource::CannotCloneRequestError),
13    /// The SSE stream failed to OPEN — transport failure or a
14    /// non-success status (401 surfaces here as `InvalidStatusCode`).
15    #[error("open daemon sse: {0}")]
16    Open(#[from] reqwest_eventsource::Error),
17    /// The stream ended before it ever opened.
18    #[error("daemon sse closed before opening")]
19    Closed,
20    /// A plain HTTP call failed in transport (or the client failed to
21    /// build).
22    #[error("daemon http: {0}")]
23    Http(#[from] reqwest::Error),
24    /// No such resource (404) — an unknown/withdrawn channel, an
25    /// unknown plugin tag.
26    #[error("not found")]
27    NotFound,
28    /// The channel offer was already accepted by someone else (409).
29    #[error("already accepted")]
30    AlreadyAccepted,
31    /// The daemon refused the credentials (401).
32    #[error("unauthorized")]
33    Unauthorized,
34    /// Any other non-success status; carries the response body text.
35    #[error("daemon status {status}: {body}")]
36    Status {
37        status: reqwest::StatusCode,
38        body: String,
39    },
40    /// A response body wasn't the expected shape.
41    #[error("daemon body parse: {0}")]
42    Parse(#[from] serde_json::Error),
43}
44
45/// The `/execute` surface's error — the [`super::Client`]'s
46/// [`CommandExecutor`](crate::cli::command::CommandExecutor)
47/// associated error type. Separate from [`Error`]: execute streams
48/// carry structured CLI errors ([`crate::cli::Error`]) that the
49/// listener surfaces never produce.
50#[cfg(feature = "cli-executor")]
51#[derive(Debug, thiserror::Error)]
52pub enum ExecuteError {
53    /// Building/sending the request, or connecting, failed.
54    #[error("connect daemon execute: {0}")]
55    Connect(reqwest::Error),
56    /// The daemon answered a non-success status (e.g. `401` on a
57    /// missing/invalid signature).
58    #[error("daemon execute http {0}: {1}")]
59    Http(reqwest::StatusCode, String),
60    /// The SSE response body failed mid-stream.
61    #[error("daemon execute sse stream: {0}")]
62    Sse(String),
63    /// Serializing the request or decoding a response event failed.
64    #[error("decode daemon execute message: {0}")]
65    Json(serde_json::Error),
66    /// Structured error emitted by the daemon on the stream.
67    #[error("{0}")]
68    Cli(crate::cli::Error),
69    /// `execute_one` was called but the stream produced no items.
70    #[error("daemon execute stream produced no items")]
71    Empty,
72}