Skip to main content

dsfb_densor_runtime/
errors.rs

1//! Error types for the densor runtime. Every failure mode is explicit and inspectable — the runtime never
2//! panics on bad input, it returns one of these.
3
4use std::fmt;
5
6/// A failure verifying a single densor object's seal.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum DensorError {
9    /// `densor_id` was empty — a densor must be identifiable.
10    EmptyId,
11    /// The recomputed evidence hash did not match the stored one (tamper / corruption).
12    EvidenceMismatch,
13}
14
15impl fmt::Display for DensorError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            DensorError::EmptyId => write!(f, "densor has an empty densor_id"),
19            DensorError::EvidenceMismatch => {
20                write!(f, "densor evidence_hash does not match its recomputed seal")
21            }
22        }
23    }
24}
25impl std::error::Error for DensorError {}
26
27/// A failure during pipeline execution. The runtime is disciplined: it refuses to execute a stage that does not
28/// declare the authority hashes it was built against, and it refuses to admit a stage whose declared authorities
29/// do not match the manifest's frozen set.
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub enum RuntimeError {
32    /// A stage declared no authority hashes — no claim may be executed without an authority anchor.
33    MissingAuthority { stage: String },
34    /// A stage's declared authority hash is not in the manifest's frozen authority set (or differs).
35    AuthorityMismatch { stage: String, authority: String },
36    /// The manifest itself is malformed (empty, duplicate ids, …).
37    ManifestInvalid(String),
38    /// The stage's `execute` reported a domain failure.
39    StageFailed { stage: String, reason: String },
40}
41
42impl fmt::Display for RuntimeError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            RuntimeError::MissingAuthority { stage } => {
46                write!(f, "stage '{stage}' declared no authority hashes (no claim without an authority anchor)")
47            }
48            RuntimeError::AuthorityMismatch { stage, authority } => {
49                write!(f, "stage '{stage}' authority '{authority}' is not in the manifest's frozen authority set")
50            }
51            RuntimeError::ManifestInvalid(why) => write!(f, "densor manifest invalid: {why}"),
52            RuntimeError::StageFailed { stage, reason } => {
53                write!(f, "stage '{stage}' failed: {reason}")
54            }
55        }
56    }
57}
58impl std::error::Error for RuntimeError {}