identity_core/
error.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur in the identity core crate.
5
6use crate::convert::Base;
7
8/// Alias for a `Result` with the error type [`Error`].
9pub type Result<T, E = Error> = ::core::result::Result<T, E>;
10
11/// This type represents all possible errors that can occur in the library.
12#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
13#[non_exhaustive]
14pub enum Error {
15  /// Caused by a failure to encode Rust types as JSON.
16  #[error("failed to encode JSON")]
17  EncodeJSON(#[source] serde_json::Error),
18  /// Caused by a failure to decode Rust types from JSON.
19  #[error("failed to decode JSON")]
20  DecodeJSON(#[source] serde_json::Error),
21  /// Caused by a failure to decode base-encoded data.
22  #[error("failed to decode {0:?} data")]
23  DecodeBase(Base, #[source] multibase::Error),
24  /// Caused by a failure to decode multibase-encoded data.
25  #[error("failed to decode multibase data")]
26  DecodeMultibase(#[source] multibase::Error),
27  /// Caused by attempting to parse an invalid `Url`.
28  #[error("invalid url")]
29  InvalidUrl(#[source] url::ParseError),
30  /// Caused by attempting to parse an invalid `Timestamp`.
31  #[error("invalid timestamp")]
32  InvalidTimestamp(#[source] time::error::Error),
33  /// Caused by attempting to create an empty `OneOrSet` instance or remove all its elements.
34  #[error("OneOrSet cannot be empty")]
35  OneOrSetEmpty,
36  /// Caused by attempting to convert a collection with duplicate keys into an OrderedSet.
37  #[error("duplicate key in OrderedSet")]
38  OrderedSetDuplicate,
39}