identity_document/error.rs
1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur when working with DID Documents.
5
6/// Alias for a [`Result`][::core::result::Result] with the error type [Error].
7pub type Result<T, E = Error> = ::core::result::Result<T, E>;
8
9/// This type represents all possible errors that can occur in the library.
10#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
11#[non_exhaustive]
12pub enum Error {
13 /// Caused by querying for a method that does not exist.
14 #[error("verification method not found")]
15 MethodNotFound,
16 /// Caused by invalid or missing properties when constructing a [`CoreDocument`](crate::document::CoreDocument).
17 #[error("invalid document property: {0}")]
18 InvalidDocument(&'static str, #[source] Option<::identity_core::Error>),
19 /// Caused by invalid or missing properties when constructing a [`Service`](crate::service::Service).
20 #[error("invalid service property: {0}")]
21 InvalidService(&'static str),
22 /// Caused by an invalid or empty fragment.
23 #[error("invalid or empty `id` fragment")]
24 MissingIdFragment,
25 /// Caused by attempting to add a verification method to a document, where a method or service with the same fragment
26 /// already exists.
27 #[error("unable to insert method: the id is already in use")]
28 MethodInsertionError,
29 /// Caused by attempting to attach or detach a relationship on an embedded method.
30 #[error("unable to modify relationships on embedded methods, use insert or remove instead")]
31 InvalidMethodEmbedded,
32 /// Caused by attempting to insert a service whose id overlaps with a verification method or an already existing
33 /// service.
34 #[error("unable to insert service: the id is already in use")]
35 InvalidServiceInsertion,
36 /// Caused by an attempt to use a method's key material in an incompatible context.
37 #[error("invalid key material")]
38 InvalidKeyMaterial(#[source] identity_verification::Error),
39 /// Caused by a failure to verify a JSON Web Signature.
40 #[error("jws verification failed")]
41 JwsVerificationError(#[source] identity_verification::jose::error::Error),
42}