Skip to main content

claim_ledger/
error.rs

1//! Error types for claim-ledger operations.
2
3use thiserror::Error;
4
5/// Errors returned by claim-ledger operations.
6#[derive(Debug, Error)]
7pub enum ClaimLedgerError {
8    /// No matching claim found in the bundle.
9    #[error("claim not found: {0}")]
10    ClaimNotFound(String),
11
12    /// No matching support judgment found.
13    #[error("support judgment not found: {0}")]
14    SupportJudgmentNotFound(String),
15
16    /// No matching evidence bundle found.
17    #[error("evidence bundle not found: {0}")]
18    EvidenceBundleNotFound(String),
19
20    /// No matching contradiction record found.
21    #[error("contradiction not found: {0}")]
22    ContradictionNotFound(String),
23
24    /// Unsupported or invalid support admission state transition.
25    #[error("invalid support state transition: {0}")]
26    InvalidSupportTransition(String),
27
28    /// Supported admissions require proof payload or explicit proof-debt waiver.
29    #[error("supported admission requires proof payload or proof debt waiver")]
30    MissingProofPayload,
31
32    /// The ledger is corrupt or verification failed.
33    #[error("ledger verification failed: {0}")]
34    LedgerCorrupt(String),
35
36    /// Serialization or deserialization failure.
37    #[error("serialization error: {0}")]
38    SerializationError(String),
39
40    /// A required input reference was not provided.
41    #[error("missing required input reference: {0}")]
42    MissingInputRef(String),
43}
44
45impl ClaimLedgerError {
46    /// Stable string discriminant for programmatic matching.
47    pub fn kind(&self) -> &'static str {
48        match self {
49            Self::ClaimNotFound(_) => "claim_not_found",
50            Self::SupportJudgmentNotFound(_) => "support_judgment_not_found",
51            Self::EvidenceBundleNotFound(_) => "evidence_bundle_not_found",
52            Self::ContradictionNotFound(_) => "contradiction_not_found",
53            Self::InvalidSupportTransition(_) => "invalid_support_transition",
54            Self::MissingProofPayload => "missing_proof_payload",
55            Self::LedgerCorrupt(_) => "ledger_corrupt",
56            Self::SerializationError(_) => "serialization_error",
57            Self::MissingInputRef(_) => "missing_input_ref",
58        }
59    }
60}