oas-document 1.1.1

OAS Identity Document types and validation for the Open Agent Specification
Documentation
// OAS Spec §5 — OAS Identity Document
//! Error types for OAS document operations.

use thiserror::Error;

/// Errors arising from OAS Identity Document operations.
#[derive(Debug, Error)]
pub enum DocumentError {
    /// The document is missing a required field.
    #[error("missing required field '{field}' in OAS Identity Document")]
    MissingField {
        /// The name of the missing field.
        field: String,
    },

    /// A field value is invalid.
    #[error("invalid value for field '{field}': {reason}")]
    InvalidField {
        /// The field name.
        field: String,
        /// Why the value is invalid.
        reason: String,
    },

    /// Document proof verification failed.
    #[error("document proof verification failed: {reason}")]
    ProofVerificationFailed {
        /// Why verification failed.
        reason: String,
    },

    /// Document proof generation failed.
    #[error("document proof generation failed: {reason}")]
    ProofGenerationFailed {
        /// Why generation failed.
        reason: String,
    },

    /// Conformance level requirements not met.
    #[error("conformance level {level} requirements not met: {reason}")]
    ConformanceNotMet {
        /// The conformance level that was not met.
        level: String,
        /// What requirement was not satisfied.
        reason: String,
    },

    /// JSON serialization/deserialization failed.
    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    /// DID parsing failed.
    #[error("DID error: {0}")]
    Did(#[from] oas_did::DidError),

    /// Cryptographic operation failed.
    #[error("crypto error: {0}")]
    Crypto(#[from] oas_crypto::CryptoError),

    /// The lifecycle status transition is not allowed.
    #[error("invalid lifecycle transition from '{from}' to '{to}'")]
    InvalidLifecycleTransition {
        /// Current status.
        from: String,
        /// Attempted new status.
        to: String,
    },

    /// Sequence number is not valid.
    #[error("invalid sequence number {sequence}: {reason}")]
    InvalidSequence {
        /// The invalid sequence number.
        sequence: u64,
        /// Why it's invalid.
        reason: String,
    },
}