Skip to main content

linera_client/
error.rs

1// Copyright (c) Zefchain Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use linera_base::{
5    crypto::ValidatorPublicKey, data_types::NetworkDescription, identifiers::ChainId,
6};
7use linera_core::node::NodeError;
8use linera_version::VersionInfo;
9
10#[cfg(not(web))]
11use crate::benchmark::BenchmarkError;
12use crate::util;
13
14/// The kinds of error that the client can return.
15#[derive(Debug, thiserror::Error)]
16#[non_exhaustive]
17pub enum Error {
18    /// An I/O operation failed.
19    #[error("I/O error: {0}")]
20    Io(#[from] std::io::Error),
21    /// A value could not be BCS-serialized or -deserialized.
22    #[error("BCS error: {0}")]
23    Bcs(#[from] bcs::Error),
24    /// An operation on a chain failed.
25    #[error("chain error: {0}")]
26    Chain(#[from] linera_chain::ChainError),
27    /// An operation performed through the chain client failed.
28    #[error("chain client error: {0}")]
29    ChainClient(#[from] linera_core::client::chain_client::Error),
30    /// The client options were invalid.
31    #[error("options error: {0}")]
32    Options(#[from] crate::client_options::Error),
33    /// An operation on the wallet backend failed.
34    #[error("wallet error: {0}")]
35    Wallet(#[source] Box<dyn std::error::Error + Send + Sync>),
36    /// An operation on a view failed.
37    #[error("view error: {0}")]
38    View(#[from] linera_views::ViewError),
39    /// An operation on the local node failed.
40    #[error("error on the local node: {0}")]
41    LocalNode(#[from] linera_core::LocalNodeError),
42    /// An operation on a remote validator failed.
43    #[error("remote node operation failed: {0}")]
44    RemoteNode(#[from] linera_core::node::NodeError),
45    /// An arithmetic operation overflowed.
46    #[error("arithmetic error: {0}")]
47    Arithmetic(#[from] linera_base::data_types::ArithmeticError),
48    /// The chain is not owned by the expected owner.
49    #[error("incorrect chain ownership")]
50    ChainOwnership,
51    /// A benchmark run failed.
52    #[cfg(not(web))]
53    #[error("Benchmark error: {0}")]
54    Benchmark(#[from] BenchmarkError),
55    /// The new chain could not be assigned to the wallet.
56    #[error("failed to assign the new chain to the wallet: {0}")]
57    AssignChain(#[source] Box<dyn std::error::Error + Send + Sync>),
58    /// The chain's ownership could not be changed.
59    #[error("failed to change chain ownership: {0}")]
60    ChangeOwnership(#[source] Box<linera_core::client::chain_client::Error>),
61    /// The module could not be published.
62    #[error("failed to publish the module: {0}")]
63    PublishModule(#[source] Box<linera_core::client::chain_client::Error>),
64    /// The data blob could not be published.
65    #[error("failed to publish the data blob: {0}")]
66    PublishDataBlob(#[source] Box<linera_core::client::chain_client::Error>),
67    /// The data blob could not be read back after publishing.
68    #[error("failed to read back the data blob: {0}")]
69    VerifyDataBlob(#[source] Box<linera_core::client::chain_client::Error>),
70    /// The messages that create the new chains could not be delivered.
71    #[error("failed to deliver the outgoing messages that create the new chains: {0}")]
72    DeliverNewChainMessages(#[source] Box<linera_core::client::chain_client::Error>),
73    /// A validator is running an incompatible version.
74    #[error("Validator version {remote} is not compatible with local version {local}.")]
75    UnexpectedVersionInfo {
76        /// The validator's version.
77        remote: Box<VersionInfo>,
78        /// Our own version.
79        local: Box<VersionInfo>,
80    },
81    /// A validator's version could not be retrieved.
82    #[error("Failed to get version information for validator {address}: {error}")]
83    UnavailableVersionInfo {
84        /// The validator's address.
85        address: String,
86        /// The underlying failure.
87        error: Box<NodeError>,
88    },
89    /// A validator disagrees with us about the network.
90    #[error("Validator's network description {remote:?} does not match our own: {local:?}.")]
91    UnexpectedNetworkDescription {
92        /// The validator's network description.
93        remote: Box<NetworkDescription>,
94        /// Our own network description.
95        local: Box<NetworkDescription>,
96    },
97    /// A validator's network description could not be retrieved.
98    #[error("Failed to get network description for validator {address}: {error}")]
99    UnavailableNetworkDescription {
100        /// The validator's address.
101        address: String,
102        /// The underlying failure.
103        error: Box<NodeError>,
104    },
105    /// A validator's signature did not verify.
106    #[error("Signature for public key {public_key} is invalid.")]
107    InvalidSignature {
108        /// The public key the signature was checked against.
109        public_key: ValidatorPublicKey,
110    },
111    /// A validator's information about a chain could not be retrieved.
112    #[error("Failed to get chain info for validator {address} and chain {chain_id}: {error}")]
113    UnavailableChainInfo {
114        /// The validator's address.
115        address: String,
116        /// The chain that was queried.
117        chain_id: ChainId,
118        /// The underlying failure.
119        error: Box<NodeError>,
120    },
121}
122
123impl Error {
124    /// Wraps an error from the wallet backend.
125    pub fn wallet(error: impl std::error::Error + Send + Sync + 'static) -> Self {
126        Self::Wallet(Box::new(error) as _)
127    }
128}
129
130util::impl_from_infallible!(Error);