Skip to main content

qualia_core_db/semantic_instruments/
errors.rs

1//! Cold-path errors for semantic-instrument collectables.
2
3use crate::bundle::BundleError;
4
5/// Fail-closed errors for manifest, canonical encoding and HMC packaging.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum InstrumentError {
8    MissingField(&'static str),
9    InvalidCategory,
10    DemoUnlabelled,
11    PathTraversal,
12    EmptyMember(&'static str),
13    EntryTooLarge { key: String, bytes: usize },
14    BundleTooLarge { bytes: usize },
15    TooManyEntries { count: usize },
16    DigestMismatch,
17    Bundle(String),
18    Canonical(String),
19    Graph(String),
20    InvalidAttestationKind,
21    SignatureAsTruth,
22    AwardIsInstrument,
23    RoleCollision,
24    Revoked,
25    Expired,
26    Tampered,
27    MissingProof,
28    RequiredMissing,
29    DigestMismatchDep,
30    DependencyCycle,
31    RevokedDependency,
32    OfflineHeld,
33    NotClosed,
34    UnknownEntryPoint,
35    MissingInput,
36    ResourceLimit,
37    Cancelled,
38    AlreadyPublished,
39    CatalogueIsNotEndorsement,
40    IncompleteDownload,
41    UnauthorisedEquivalence,
42    EvaluatorPassIsNotIssuance,
43    PrivateEvidence,
44}
45
46impl std::fmt::Display for InstrumentError {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        match self {
49            Self::MissingField(name) => write!(f, "instrument: missing {name}"),
50            Self::InvalidCategory => write!(
51                f,
52                "instrument: content category is not Demo/Reference/Operational"
53            ),
54            Self::DemoUnlabelled => {
55                write!(f, "instrument: Demo category requires an explicit demonstration/development notice")
56            }
57            Self::PathTraversal => write!(f, "instrument: member key is not a relative safe path"),
58            Self::EmptyMember(key) => write!(f, "instrument: empty member {key}"),
59            Self::EntryTooLarge { key, bytes } => {
60                write!(f, "instrument: entry {key} is {bytes} bytes (over budget)")
61            }
62            Self::BundleTooLarge { bytes } => {
63                write!(f, "instrument: collectable is {bytes} bytes (over budget)")
64            }
65            Self::TooManyEntries { count } => {
66                write!(f, "instrument: {count} members exceeds the collectable cap")
67            }
68            Self::DigestMismatch => write!(
69                f,
70                "instrument: content digest does not match canonical bytes"
71            ),
72            Self::Bundle(msg) => write!(f, "instrument bundle: {msg}"),
73            Self::Canonical(msg) => write!(f, "instrument canonical: {msg}"),
74            Self::Graph(msg) => write!(f, "instrument graph: {msg}"),
75            Self::InvalidAttestationKind => write!(f, "instrument: unknown attestation kind"),
76            Self::SignatureAsTruth => {
77                write!(
78                    f,
79                    "instrument: a signature is origin, not substantive truth"
80                )
81            }
82            Self::AwardIsInstrument => {
83                write!(
84                    f,
85                    "instrument: capability award subject must not be the instrument"
86                )
87            }
88            Self::RoleCollision => {
89                write!(
90                    f,
91                    "instrument: authorship/review/publication/issuance must stay distinct"
92                )
93            }
94            Self::Revoked => write!(f, "instrument: attestation is revoked for future reliance"),
95            Self::Expired => write!(f, "instrument: attestation expired"),
96            Self::Tampered => write!(f, "instrument: attestation tampered"),
97            Self::MissingProof => write!(f, "instrument: attestation missing proof"),
98            Self::RequiredMissing => write!(f, "instrument: required dependency missing"),
99            Self::DigestMismatchDep => write!(f, "instrument: dependency digest mismatch"),
100            Self::DependencyCycle => write!(f, "instrument: dependency cycle"),
101            Self::RevokedDependency => write!(f, "instrument: required dependency revoked"),
102            Self::OfflineHeld => write!(f, "instrument: offline; required dependency unresolved"),
103            Self::NotClosed => write!(f, "instrument: cannot activate before verified closure"),
104            Self::UnknownEntryPoint => write!(f, "instrument: unknown entry point (not a Host ID)"),
105            Self::MissingInput => write!(f, "instrument: required input missing (held)"),
106            Self::ResourceLimit => write!(f, "instrument: resource limit reached"),
107            Self::Cancelled => write!(f, "instrument: execution cancelled"),
108            Self::AlreadyPublished => {
109                write!(f, "instrument: same release cannot accept different bytes")
110            }
111            Self::CatalogueIsNotEndorsement => {
112                write!(f, "instrument: catalogue listing is not endorsement")
113            }
114            Self::IncompleteDownload => {
115                write!(
116                    f,
117                    "instrument: interrupted download cannot register as resolved"
118                )
119            }
120            Self::UnauthorisedEquivalence => {
121                write!(f, "instrument: unauthorised capability equivalence")
122            }
123            Self::EvaluatorPassIsNotIssuance => {
124                write!(f, "instrument: a runner pass is not an award issuance")
125            }
126            Self::PrivateEvidence => {
127                write!(
128                    f,
129                    "instrument: private evidence must not enter a public award"
130                )
131            }
132        }
133    }
134}
135
136impl std::error::Error for InstrumentError {}
137
138impl From<BundleError> for InstrumentError {
139    fn from(value: BundleError) -> Self {
140        Self::Bundle(value.to_string())
141    }
142}