kindling_client/error.rs
1//! Client error type.
2
3use std::io;
4
5use thiserror::Error;
6
7/// Errors returned by [`Client`](crate::Client) operations.
8#[derive(Debug, Error)]
9pub enum ClientError {
10 /// The daemon could not be reached or spawned within the connect budget.
11 ///
12 /// Carries a human-readable explanation (e.g. "spawner failed" or
13 /// "socket never appeared within 1s").
14 #[error("kindling daemon unavailable: {0}")]
15 Unavailable(String),
16
17 /// A transport-level failure talking HTTP/1 over the socket (hyper).
18 #[error("http transport error: {0}")]
19 Http(String),
20
21 /// The daemon returned a non-2xx response. The `message` is the daemon's
22 /// `{ "error": "<msg>" }` body when present, else the raw body or a status
23 /// phrase.
24 #[error("daemon returned {status}: {message}")]
25 Api {
26 /// HTTP status code.
27 status: u16,
28 /// Error message extracted from the daemon's JSON body.
29 message: String,
30 },
31
32 /// The daemon's reported `schemaVersion` does not match the version this
33 /// client was built/configured to expect. Fail loud rather than risk
34 /// silent contract drift.
35 #[error("schema version mismatch: client expected {expected}, daemon reports {actual}")]
36 SchemaMismatch {
37 /// Schema version the client expects.
38 expected: u32,
39 /// Schema version the daemon reports.
40 actual: u32,
41 },
42
43 /// A 2xx response body could not be decoded into the expected type.
44 #[error("failed to decode daemon response: {0}")]
45 Decode(String),
46
47 /// A low-level I/O error (socket connect, spawn) not otherwise classified.
48 #[error("io error: {0}")]
49 Io(#[from] io::Error),
50}