Skip to main content

el_core/
error.rs

1//! Domain error type.
2
3use core::fmt;
4
5/// Errors surfaced by the SDK. Variants carry only static descriptors and
6/// numeric context — never user content.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum EdgeError {
9    /// Attempted to load/use a model that has not reached `Verified`
10    /// (ADR-006 hard load gate).
11    UnverifiedModel,
12    /// Model signature verification failed (ADR-006).
13    SignatureRejected,
14    /// Operation invalid for the current session phase (ADR-001 state machine).
15    InvalidPhase {
16        expected: &'static str,
17        found: &'static str,
18    },
19    /// The static memory plan exceeds the configured budget (ADR-003).
20    MemoryBudgetExceeded { requested: u64, budget: u64 },
21    /// A network egress was attempted while air-gapped (ADR-004).
22    AirGapViolation,
23    /// Engine/adapter failure (message is a static descriptor, not user data).
24    Engine(&'static str),
25    /// Cloud request failed (ADR-010). Carries a heap-allocated message so
26    /// dynamic error strings (HTTP status, URL) can be included without leaking.
27    CloudRequest(Box<str>),
28    /// Grammar constraint error (ADR-004). Heap-allocated for the same reason.
29    Grammar(Box<str>),
30}
31
32impl fmt::Display for EdgeError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            EdgeError::UnverifiedModel => {
36                write!(f, "model is not verified; refusing to load (ADR-006)")
37            }
38            EdgeError::SignatureRejected => write!(f, "model signature rejected (ADR-006)"),
39            EdgeError::InvalidPhase { expected, found } => {
40                write!(f, "invalid phase: expected {expected}, found {found}")
41            }
42            EdgeError::MemoryBudgetExceeded { requested, budget } => {
43                write!(
44                    f,
45                    "memory plan needs {requested} bytes > budget {budget} (ADR-003)"
46                )
47            }
48            EdgeError::AirGapViolation => {
49                write!(f, "network egress attempted while air-gapped (ADR-004)")
50            }
51            EdgeError::Engine(msg) => write!(f, "engine error: {msg}"),
52            EdgeError::CloudRequest(msg) => write!(f, "cloud request: {msg}"),
53            EdgeError::Grammar(msg) => write!(f, "grammar constraint: {msg}"),
54        }
55    }
56}
57
58impl std::error::Error for EdgeError {}
59
60/// SDK result alias.
61pub type Result<T> = core::result::Result<T, EdgeError>;