Skip to main content

libgrite_ipc/
error.rs

1//! IPC error types
2
3use thiserror::Error;
4
5/// Errors that can occur during IPC operations
6#[derive(Error, Debug)]
7pub enum IpcError {
8    /// Connection failed
9    #[error("Connection failed: {0}")]
10    ConnectionFailed(String),
11
12    /// Request timed out
13    #[error("Request timed out after {0}ms")]
14    Timeout(u64),
15
16    /// Serialization error
17    #[error("Serialization error: {0}")]
18    Serialization(String),
19
20    /// Deserialization error
21    #[error("Deserialization error: {0}")]
22    Deserialization(String),
23
24    /// Protocol version mismatch
25    #[error("Protocol version mismatch: expected {expected}, got {actual}")]
26    VersionMismatch { expected: u32, actual: u32 },
27
28    /// Daemon not running
29    #[error("Daemon not running")]
30    DaemonNotRunning,
31
32    /// Daemon returned an error
33    #[error("Daemon error [{code}]: {message}")]
34    DaemonError { code: String, message: String },
35
36    /// Lock file error
37    #[error("Lock file error: {0}")]
38    LockFile(String),
39
40    /// Lock is held by another process
41    #[error("Lock held by process {pid} (expires in {expires_in_ms}ms)")]
42    LockHeld { pid: u32, expires_in_ms: u64 },
43
44    /// Lock has expired
45    #[error("Lock expired")]
46    LockExpired,
47
48    /// IO error
49    #[error("IO error: {0}")]
50    Io(#[from] std::io::Error),
51
52    /// JSON error
53    #[error("JSON error: {0}")]
54    Json(#[from] serde_json::Error),
55
56    /// NNG error
57    #[error("NNG error: {0}")]
58    Nng(String),
59}
60
61impl From<nng::Error> for IpcError {
62    fn from(e: nng::Error) -> Self {
63        IpcError::Nng(e.to_string())
64    }
65}
66
67/// Error codes matching docs/cli-json.md
68pub mod codes {
69    pub const DB_BUSY: &str = "db_busy";
70    pub const NOT_FOUND: &str = "not_found";
71    pub const INVALID_INPUT: &str = "invalid_input";
72    pub const INTERNAL: &str = "internal";
73    pub const NOT_INITIALIZED: &str = "not_initialized";
74    pub const IO_ERROR: &str = "io_error";
75    pub const GIT_ERROR: &str = "git_error";
76    pub const IPC_ERROR: &str = "ipc_error";
77}