Skip to main content

spn_client/
error.rs

1//! Error types for spn-client.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur when communicating with the spn daemon.
7#[derive(Debug, Error)]
8pub enum Error {
9    /// Failed to connect to the daemon socket.
10    #[error("Failed to connect to spn daemon at {path}: {source}")]
11    ConnectionFailed {
12        path: PathBuf,
13        #[source]
14        source: std::io::Error,
15    },
16
17    /// Not connected to the daemon (shouldn't happen in normal use).
18    #[error("Not connected to spn daemon")]
19    NotConnected,
20
21    /// The requested secret was not found.
22    #[error("Secret not found for provider '{provider}': {details}")]
23    SecretNotFound { provider: String, details: String },
24
25    /// The daemon returned an error.
26    #[error("Daemon error: {0}")]
27    DaemonError(String),
28
29    /// Unexpected response from daemon.
30    #[error("Unexpected response from daemon")]
31    UnexpectedResponse,
32
33    /// Response too large (potential attack or bug).
34    #[error("Response too large: {0} bytes")]
35    ResponseTooLarge(usize),
36
37    /// IO error during communication.
38    #[error("IO error: {0}")]
39    IoError(#[from] std::io::Error),
40
41    /// Failed to serialize request.
42    #[error("Failed to serialize request: {0}")]
43    SerializationError(#[source] serde_json::Error),
44
45    /// Failed to deserialize response.
46    #[error("Failed to deserialize response: {0}")]
47    DeserializationError(#[source] serde_json::Error),
48
49    /// Configuration error (e.g., HOME not set).
50    #[error("Configuration error: {0}")]
51    Configuration(String),
52
53    /// Request timed out.
54    #[error("Request timed out after {0} seconds")]
55    Timeout(u64),
56
57    /// Protocol version mismatch between client and daemon.
58    #[error("Protocol version mismatch: client v{client}, daemon v{daemon}")]
59    ProtocolMismatch { client: u32, daemon: u32 },
60}