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