Skip to main content

oas_document/
error.rs

1// OAS Spec §5 — OAS Identity Document
2//! Error types for OAS document operations.
3
4use thiserror::Error;
5
6/// Errors arising from OAS Identity Document operations.
7#[derive(Debug, Error)]
8pub enum DocumentError {
9    /// The document is missing a required field.
10    #[error("missing required field '{field}' in OAS Identity Document")]
11    MissingField {
12        /// The name of the missing field.
13        field: String,
14    },
15
16    /// A field value is invalid.
17    #[error("invalid value for field '{field}': {reason}")]
18    InvalidField {
19        /// The field name.
20        field: String,
21        /// Why the value is invalid.
22        reason: String,
23    },
24
25    /// Document proof verification failed.
26    #[error("document proof verification failed: {reason}")]
27    ProofVerificationFailed {
28        /// Why verification failed.
29        reason: String,
30    },
31
32    /// Document proof generation failed.
33    #[error("document proof generation failed: {reason}")]
34    ProofGenerationFailed {
35        /// Why generation failed.
36        reason: String,
37    },
38
39    /// Conformance level requirements not met.
40    #[error("conformance level {level} requirements not met: {reason}")]
41    ConformanceNotMet {
42        /// The conformance level that was not met.
43        level: String,
44        /// What requirement was not satisfied.
45        reason: String,
46    },
47
48    /// JSON serialization/deserialization failed.
49    #[error("JSON error: {0}")]
50    Json(#[from] serde_json::Error),
51
52    /// DID parsing failed.
53    #[error("DID error: {0}")]
54    Did(#[from] oas_did::DidError),
55
56    /// Cryptographic operation failed.
57    #[error("crypto error: {0}")]
58    Crypto(#[from] oas_crypto::CryptoError),
59
60    /// The lifecycle status transition is not allowed.
61    #[error("invalid lifecycle transition from '{from}' to '{to}'")]
62    InvalidLifecycleTransition {
63        /// Current status.
64        from: String,
65        /// Attempted new status.
66        to: String,
67    },
68
69    /// Sequence number is not valid.
70    #[error("invalid sequence number {sequence}: {reason}")]
71    InvalidSequence {
72        /// The invalid sequence number.
73        sequence: u64,
74        /// Why it's invalid.
75        reason: String,
76    },
77}