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;
9use thiserror_context::Context;
10
11#[cfg(not(web))]
12use crate::benchmark::BenchmarkError;
13use crate::util;
14
15#[derive(Debug, thiserror::Error)]
16#[non_exhaustive]
17pub(crate) enum Inner {
18    #[error("I/O error: {0}")]
19    Io(#[from] std::io::Error),
20    #[error("BCS error: {0}")]
21    Bcs(#[from] bcs::Error),
22    #[error("chain error: {0}")]
23    Chain(#[from] linera_chain::ChainError),
24    #[error("chain client error: {0}")]
25    ChainClient(#[from] linera_core::client::chain_client::Error),
26    #[error("options error: {0}")]
27    Options(#[from] crate::client_options::Error),
28    #[error("wallet error: {0}")]
29    Wallet(#[source] Box<dyn std::error::Error + Send + Sync>),
30    #[error("view error: {0}")]
31    View(#[from] linera_views::ViewError),
32    #[error("error on the local node: {0}")]
33    LocalNode(#[from] linera_core::LocalNodeError),
34    #[error("remote node operation failed: {0}")]
35    RemoteNode(#[from] linera_core::node::NodeError),
36    #[error("arithmetic error: {0}")]
37    Arithmetic(#[from] linera_base::data_types::ArithmeticError),
38    #[error("incorrect chain ownership")]
39    ChainOwnership,
40    #[cfg(not(web))]
41    #[error("Benchmark error: {0}")]
42    Benchmark(#[from] BenchmarkError),
43    #[error("Validator version {remote} is not compatible with local version {local}.")]
44    UnexpectedVersionInfo {
45        remote: Box<VersionInfo>,
46        local: Box<VersionInfo>,
47    },
48    #[error("Failed to get version information for validator {address}: {error}")]
49    UnavailableVersionInfo {
50        address: String,
51        error: Box<NodeError>,
52    },
53    #[error("Validator's network description {remote:?} does not match our own: {local:?}.")]
54    UnexpectedNetworkDescription {
55        remote: Box<NetworkDescription>,
56        local: Box<NetworkDescription>,
57    },
58    #[error("Failed to get network description for validator {address}: {error}")]
59    UnavailableNetworkDescription {
60        address: String,
61        error: Box<NodeError>,
62    },
63    #[error("Signature for public key {public_key} is invalid.")]
64    InvalidSignature { public_key: ValidatorPublicKey },
65    #[error("Failed to get chain info for validator {address} and chain {chain_id}: {error}")]
66    UnavailableChainInfo {
67        address: String,
68        chain_id: ChainId,
69        error: Box<NodeError>,
70    },
71    #[error("Chain {0} not found in wallet")]
72    UnknownChainId(ChainId),
73}
74
75impl Inner {
76    pub fn wallet(error: impl std::error::Error + Send + Sync + 'static) -> Self {
77        Self::Wallet(Box::new(error) as _)
78    }
79}
80
81thiserror_context::impl_context!(Error(Inner));
82
83impl Error {
84    pub(crate) fn wallet(error: impl std::error::Error + Send + Sync + 'static) -> Self {
85        Inner::wallet(error).into()
86    }
87}
88
89util::impl_from_infallible!(Error);