identity_iota_core/rebased/
error.rs

1// Copyright 2020-2024 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Errors that may occur for the rebased logic.
5
6use crate::iota_interaction_adapter::AdapterError;
7
8/// This type represents all possible errors that can occur in the library.
9#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
10#[non_exhaustive]
11pub enum Error {
12  /// failed to connect to network.
13  #[error("failed to connect to iota network node; {0:?}")]
14  Network(String, #[source] iota_interaction::error::Error),
15  /// could not lookup an object ID.
16  #[error("failed to lookup an object; {0}")]
17  ObjectLookup(String),
18  /// MigrationRegistry error.
19  #[error(transparent)]
20  MigrationRegistryNotFound(crate::rebased::migration::Error),
21  /// Caused by a look failures during resolution.
22  #[error("DID resolution failed: {0}")]
23  DIDResolutionError(String),
24  /// Caused by invalid or missing arguments.
25  #[error("invalid or missing argument: {0}")]
26  InvalidArgument(String),
27  /// Caused by invalid keys.
28  #[error("invalid key: {0}")]
29  InvalidKey(String),
30  /// Caused by issues with paying for transaction.
31  #[error("issue with gas for transaction: {0}")]
32  GasIssue(String),
33  /// Could not parse module, package, etc.
34  #[error("failed to parse {0}")]
35  ParsingFailed(String),
36  /// Could not build transaction.
37  #[error("failed to build transaction; {0}")]
38  TransactionBuildingFailed(String),
39  /// Could not sign transaction.
40  #[error("failed to sign transaction; {0}")]
41  TransactionSigningFailed(String),
42  /// Could not execute transaction.
43  #[error("transaction execution failed; {0}")]
44  TransactionExecutionFailed(#[from] iota_interaction::error::Error),
45  /// Transaction yielded invalid response. This usually means that the transaction was executed but did not produce
46  /// the expected result.
47  #[error("transaction returned an unexpected response; {0}")]
48  TransactionUnexpectedResponse(String),
49  /// A transaction was successfully executed on the ledger, but its off-chain logic couldn't be applied.
50  #[error("failed to parse transaction effects: {source}")]
51  TransactionOffChainApplicationFailure {
52    /// The actual error coming from `apply`.
53    #[source]
54    source: Box<Self>,
55    /// The raw RPC response, as received by the client.
56    // Dev-comment: Neeeded to box this to avoid clippy complaining about the size of this variant.
57    #[cfg(not(target_arch = "wasm32"))]
58    response: Box<iota_interaction::rpc_types::IotaTransactionBlockResponse>,
59    /// JSON-encoded string representation for the actual execution's RPC response.
60    #[cfg(target_arch = "wasm32")]
61    response: String,
62  },
63  /// Config is invalid.
64  #[error("invalid config: {0}")]
65  InvalidConfig(String),
66  /// Failed to parse DID document.
67  #[error("failed to parse DID document; {0}")]
68  DidDocParsingFailed(String),
69  /// Failed to serialize DID document.
70  #[error("failed to serialize DID document; {0}")]
71  DidDocSerialization(String),
72  /// Identity related error.
73  #[error("identity error; {0}")]
74  Identity(String),
75  #[error("unexpected state when looking up identity history; {0}")]
76  /// Unexpected state when looking up identity history.
77  InvalidIdentityHistory(String),
78  /// An operation cannot be carried on for a lack of permissions - e.g. missing capability.
79  #[error("the requested operation cannot be performed for a lack of permissions; {0}")]
80  MissingPermission(String),
81  /// An error caused by either a connection issue or an invalid RPC call.
82  #[error("RPC error: {0}")]
83  RpcError(String),
84  /// An error caused by a bcs serialization or deserialization.
85  #[error("BCS error: {0}")]
86  BcsError(#[from] bcs::Error),
87  /// An anyhow::error.
88  #[error("Any error: {0}")]
89  AnyError(#[from] anyhow::Error),
90  /// An error caused by a foreign function interface call.
91  #[error("FFI error: {0}")]
92  FfiError(String),
93  /// Caused by an interaction with the IOTA protocol.
94  #[error("IOTA interaction error")]
95  IotaInteractionError(#[source] iota_interaction::interaction_error::Error),
96  /// Caused by a platform-specific adapter to interact with the IOTA protocol.
97  #[error("TsSdkError: {0}")]
98  IotaInteractionAdapterError(#[from] AdapterError),
99}
100
101/// Can be used for example like `map_err(rebased_err)` to convert other error
102///  types to identity_iota_core::rebased::Error.
103pub fn rebased_err<T>(error: T) -> Error
104where
105  Error: From<T>,
106{
107  error.into()
108}