nodedb_types/error/
code.rs1use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub struct ErrorCode(pub u16);
10
11impl ErrorCode {
12 pub const CONSTRAINT_VIOLATION: Self = Self(1000);
14 pub const WRITE_CONFLICT: Self = Self(1001);
15 pub const DEADLINE_EXCEEDED: Self = Self(1002);
16 pub const PREVALIDATION_REJECTED: Self = Self(1003);
17 pub const APPEND_ONLY_VIOLATION: Self = Self(1010);
18 pub const BALANCE_VIOLATION: Self = Self(1011);
19 pub const PERIOD_LOCKED: Self = Self(1012);
20 pub const STATE_TRANSITION_VIOLATION: Self = Self(1013);
21 pub const TRANSITION_CHECK_VIOLATION: Self = Self(1014);
22 pub const RETENTION_VIOLATION: Self = Self(1015);
23 pub const LEGAL_HOLD_ACTIVE: Self = Self(1016);
24 pub const TYPE_MISMATCH: Self = Self(1020);
25 pub const OVERFLOW: Self = Self(1021);
26 pub const INSUFFICIENT_BALANCE: Self = Self(1022);
27 pub const RATE_EXCEEDED: Self = Self(1023);
28 pub const TYPE_GUARD_VIOLATION: Self = Self(1024);
29
30 pub const COLLECTION_NOT_FOUND: Self = Self(1100);
32 pub const DOCUMENT_NOT_FOUND: Self = Self(1101);
33 pub const COLLECTION_DRAINING: Self = Self(1102);
34 pub const COLLECTION_DEACTIVATED: Self = Self(1103);
35
36 pub const PLAN_ERROR: Self = Self(1200);
38 pub const FAN_OUT_EXCEEDED: Self = Self(1201);
39 pub const SQL_NOT_ENABLED: Self = Self(1202);
40
41 pub const AUTHORIZATION_DENIED: Self = Self(2000);
43 pub const AUTH_EXPIRED: Self = Self(2001);
44
45 pub const SYNC_CONNECTION_FAILED: Self = Self(3000);
47 pub const SYNC_DELTA_REJECTED: Self = Self(3001);
48 pub const SHAPE_SUBSCRIPTION_FAILED: Self = Self(3002);
49
50 pub const STORAGE: Self = Self(4000);
52 pub const SEGMENT_CORRUPTED: Self = Self(4001);
53 pub const COLD_STORAGE: Self = Self(4002);
54
55 pub const WAL: Self = Self(4100);
57
58 pub const SERIALIZATION: Self = Self(4200);
60 pub const CODEC: Self = Self(4201);
61
62 pub const CONFIG: Self = Self(5000);
64 pub const BAD_REQUEST: Self = Self(5001);
65
66 pub const NO_LEADER: Self = Self(6000);
68 pub const NOT_LEADER: Self = Self(6001);
69 pub const MIGRATION_IN_PROGRESS: Self = Self(6002);
70 pub const NODE_UNREACHABLE: Self = Self(6003);
71 pub const CLUSTER: Self = Self(6010);
72
73 pub const MEMORY_EXHAUSTED: Self = Self(7000);
75
76 pub const ENCRYPTION: Self = Self(8000);
78
79 pub const INTERNAL: Self = Self(9000);
81 pub const BRIDGE: Self = Self(9001);
82 pub const DISPATCH: Self = Self(9002);
83}
84
85impl fmt::Display for ErrorCode {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 write!(f, "NDB-{:04}", self.0)
88 }
89}
90
91#[cfg(test)]
92mod tests {
93 use super::*;
94
95 #[test]
96 fn error_code_display() {
97 assert_eq!(ErrorCode::CONSTRAINT_VIOLATION.to_string(), "NDB-1000");
98 assert_eq!(ErrorCode::INTERNAL.to_string(), "NDB-9000");
99 assert_eq!(ErrorCode::WAL.to_string(), "NDB-4100");
100 }
101}