eliciter_core/error.rs
1//! Kernel error type with stable, machine-parseable prefixes (spec §5).
2//!
3//! The `Display` output of each variant begins with a stable uppercase code
4//! (`SESSION_NOT_FOUND`, `INVALID_CLAIM`, `BAD_SESSION_ID`, …) — the
5//! cpm-planner convention — so the MCP server can surface them verbatim and
6//! clients can pattern-match on the prefix.
7
8use thiserror::Error;
9
10/// All errors the kernel can return. Each `Display` begins with a stable code.
11#[derive(Debug, Error)]
12pub enum EngineError {
13 /// The referenced session has no event log.
14 #[error("SESSION_NOT_FOUND: no session '{0}'")]
15 SessionNotFound(String),
16
17 /// The session id is empty or contains path-unsafe characters.
18 #[error("BAD_SESSION_ID: {0}")]
19 BadSessionId(String),
20
21 /// A claim payload is structurally invalid (empty id, predicate, etc.).
22 #[error("INVALID_CLAIM: {0}")]
23 InvalidClaim(String),
24
25 /// An evidence payload is invalid (e.g. references an unknown claim).
26 #[error("INVALID_EVIDENCE: {0}")]
27 InvalidEvidence(String),
28
29 /// A remediation payload is invalid (e.g. unknown target).
30 #[error("INVALID_REMEDIATION: {0}")]
31 InvalidRemediation(String),
32
33 /// A referenced claim does not exist in the session.
34 #[error("CLAIM_NOT_FOUND: no claim '{0}'")]
35 ClaimNotFound(String),
36
37 /// A referenced contradiction does not currently exist.
38 #[error("CONTRADICTION_NOT_FOUND: no contradiction '{0}'")]
39 ContradictionNotFound(String),
40
41 /// A duplicate claim/event id was submitted.
42 #[error("DUPLICATE_ID: {0}")]
43 DuplicateId(String),
44
45 /// Underlying store I/O failure.
46 #[error("STORE_ERROR: {0}")]
47 StoreError(String),
48}
49
50/// Convenience result alias.
51pub type Result<T> = std::result::Result<T, EngineError>;