Skip to main content

dpp_domain/error/
dpp.rs

1//! Top-level error type for the DPP domain.
2
3use thiserror::Error;
4
5use crate::field_error::ValidationErrors;
6
7/// Top-level error type for the DPP domain.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum DppError {
11    #[error("passport not found: {0}")]
12    NotFound(String),
13
14    #[error(
15        "passport is not in a state that allows this operation: current={current}, required={required}"
16    )]
17    InvalidTransition { current: String, required: String },
18
19    #[error("validation failed: {0}")]
20    Validation(ValidationErrors),
21
22    #[error("signing failed: {0}")]
23    Signing(String),
24
25    #[error("serialisation error: {0}")]
26    Serialisation(String),
27
28    /// A stored document's product group data predates the current schema by more
29    /// than the registered lens chain can bridge — e.g. a required field the
30    /// document was written before, with no source data anywhere to derive it
31    /// from. Not a bug to fix by writing a lens: some gaps have no honest
32    /// transform. See [`crate::schemas::lens`].
33    #[error("stored data does not match the current schema: {0}")]
34    SchemaIncompatible(#[from] crate::schemas::lens::UpcastError),
35
36    /// Returned when an attempt is made to delete or overwrite a passport that
37    /// has been published and is therefore subject to EU ESPR retention obligations.
38    /// Published passports must remain accessible for the legally defined period
39    /// under the applicable delegated act (typically 10–15 years).
40    #[error("passport is retention-locked: published passports cannot be deleted")]
41    RetentionLocked,
42
43    #[error("internal error: {0}")]
44    Internal(String),
45}
46
47impl From<ValidationErrors> for DppError {
48    fn from(errors: ValidationErrors) -> Self {
49        DppError::Validation(errors)
50    }
51}