icydb_core/
error.rs

1use std::fmt;
2use thiserror::Error as ThisError;
3
4///
5/// InternalError
6/// Structured runtime error with a stable internal classification.
7/// Not a stable API; intended for internal use and may change without notice.
8///
9
10#[derive(Debug, ThisError)]
11#[error("{message}")]
12pub struct InternalError {
13    pub class: ErrorClass,
14    pub origin: ErrorOrigin,
15    pub message: String,
16}
17
18impl InternalError {
19    pub fn new(class: ErrorClass, origin: ErrorOrigin, message: impl Into<String>) -> Self {
20        Self {
21            class,
22            origin,
23            message: message.into(),
24        }
25    }
26
27    #[must_use]
28    pub fn display_with_class(&self) -> String {
29        format!("{}:{}: {}", self.origin, self.class, self.message)
30    }
31}
32
33///
34/// ErrorClass
35/// Internal error taxonomy for runtime classification.
36/// Not a stable API; may change without notice.
37///
38
39#[derive(Clone, Copy, Debug, Eq, PartialEq)]
40pub enum ErrorClass {
41    Corruption,
42    Internal,
43    Conflict,
44    Unsupported,
45    InvariantViolation,
46}
47
48impl fmt::Display for ErrorClass {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        let label = match self {
51            Self::Corruption => "corruption",
52            Self::Internal => "internal",
53            Self::Conflict => "conflict",
54            Self::Unsupported => "unsupported",
55            Self::InvariantViolation => "invariant_violation",
56        };
57        write!(f, "{label}")
58    }
59}
60
61///
62/// ErrorOrigin
63/// Internal origin taxonomy for runtime classification.
64/// Not a stable API; may change without notice.
65///
66
67#[derive(Clone, Copy, Debug, Eq, PartialEq)]
68pub enum ErrorOrigin {
69    Serialize,
70    Store,
71    Index,
72    Query,
73    Response,
74    Executor,
75    Interface,
76}
77
78impl fmt::Display for ErrorOrigin {
79    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80        let label = match self {
81            Self::Serialize => "serialize",
82            Self::Store => "store",
83            Self::Index => "index",
84            Self::Query => "query",
85            Self::Response => "response",
86            Self::Executor => "executor",
87            Self::Interface => "interface",
88        };
89        write!(f, "{label}")
90    }
91}