1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum IpcError {
8 #[error("Connection failed: {0}")]
10 ConnectionFailed(String),
11
12 #[error("Request timed out after {0}ms")]
14 Timeout(u64),
15
16 #[error("Serialization error: {0}")]
18 Serialization(String),
19
20 #[error("Deserialization error: {0}")]
22 Deserialization(String),
23
24 #[error("Protocol version mismatch: expected {expected}, got {actual}")]
26 VersionMismatch { expected: u32, actual: u32 },
27
28 #[error("Daemon not running")]
30 DaemonNotRunning,
31
32 #[error("Daemon error [{code}]: {message}")]
34 DaemonError { code: String, message: String },
35
36 #[error("Lock file error: {0}")]
38 LockFile(String),
39
40 #[error("Lock held by process {pid} (expires in {expires_in_ms}ms)")]
42 LockHeld { pid: u32, expires_in_ms: u64 },
43
44 #[error("Lock expired")]
46 LockExpired,
47
48 #[error("IO error: {0}")]
50 Io(#[from] std::io::Error),
51
52 #[error("JSON error: {0}")]
54 Json(#[from] serde_json::Error),
55
56 #[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
67pub 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}