use thiserror::Error;
use crate::field_error::ValidationErrors;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum DppError {
#[error("passport not found: {0}")]
NotFound(String),
#[error(
"passport is not in a state that allows this operation: current={current}, required={required}"
)]
InvalidTransition { current: String, required: String },
#[error("validation failed: {0}")]
Validation(ValidationErrors),
#[error("signing failed: {0}")]
Signing(String),
#[error("serialisation error: {0}")]
Serialisation(String),
#[error(
"stored document carries removed envelope key `{removed}`, which was renamed to \
`{replacement}`: reading it would silently drop the field, so it is refused"
)]
RemovedEnvelopeKey {
removed: &'static str,
replacement: &'static str,
},
#[error("stored data does not match the current schema: {0}")]
SchemaIncompatible(#[from] crate::schemas::lens::UpcastError),
#[error("passport is retention-locked: published passports cannot be deleted")]
RetentionLocked,
#[error("cannot resolve what supersedes passport {id}: {reason}")]
SuccessionUnresolvable {
id: String,
reason: String,
},
#[error("internal error: {0}")]
Internal(String),
}
impl From<ValidationErrors> for DppError {
fn from(errors: ValidationErrors) -> Self {
DppError::Validation(errors)
}
}