celestia_grpc/
error.rs

1use celestia_types::hash::Hash;
2use celestia_types::state::ErrorCode;
3use k256::ecdsa::signature::Error as SignatureError;
4use tonic::Status;
5
6use crate::abci_proofs::ProofError;
7
8/// Alias for a `Result` with the error type [`celestia_grpc::Error`].
9///
10/// [`celestia_grpc::Error`]: crate::Error
11pub type Result<T, E = Error> = std::result::Result<T, E>;
12
13/// Representation of all the errors that can occur when interacting with [`GrpcClient`].
14///
15/// [`GrpcClient`]: crate::GrpcClient
16#[derive(Debug, thiserror::Error)]
17pub enum Error {
18    /// Tonic error
19    #[error(transparent)]
20    TonicError(Box<Status>),
21
22    /// Transport error
23    #[cfg(not(target_arch = "wasm32"))]
24    #[error("Transport: {0}")]
25    TransportError(#[from] tonic::transport::Error),
26
27    /// Tendermint Error
28    #[error(transparent)]
29    TendermintError(#[from] tendermint::Error),
30
31    /// Celestia types error
32    #[error(transparent)]
33    CelestiaTypesError(#[from] celestia_types::Error),
34
35    /// Tendermint Proto Error
36    #[error(transparent)]
37    TendermintProtoError(#[from] tendermint_proto::Error),
38
39    /// Failed to parse gRPC response
40    #[error("Failed to parse response")]
41    FailedToParseResponse,
42
43    /// Unexpected reponse type
44    #[error("Unexpected response type")]
45    UnexpectedResponseType(String),
46
47    /// Empty blob submission list
48    #[error("Attempted to submit blob transaction with empty blob list")]
49    TxEmptyBlobList,
50
51    /// Broadcasting transaction failed
52    #[error("Broadcasting transaction {0} failed; code: {1}, error: {2}")]
53    TxBroadcastFailed(Hash, ErrorCode, String),
54
55    /// Executing transaction failed
56    #[error("Transaction {0} execution failed; code: {1}, error: {2}")]
57    TxExecutionFailed(Hash, ErrorCode, String),
58
59    /// Transaction was rejected
60    #[error("Transaction {0} was rejected; code: {1}, error: {2}")]
61    TxRejected(Hash, ErrorCode, String),
62
63    /// Transaction was evicted from the mempool
64    #[error("Transaction {0} was evicted from the mempool")]
65    TxEvicted(Hash),
66
67    /// Transaction wasn't found, it was likely rejected
68    #[error("Transaction {0} wasn't found, it was likely rejected")]
69    TxNotFound(Hash),
70
71    /// Provided public key differs from one associated with account
72    #[error("Provided public key differs from one associated with account")]
73    PublicKeyMismatch,
74
75    /// ABCI proof verification has failed
76    #[error("ABCI proof verification has failed: {0}")]
77    AbciProof(#[from] ProofError),
78
79    /// ABCI query returned an error
80    #[error("ABCI query returned an error (code {0}): {1}")]
81    AbciQuery(ErrorCode, String),
82
83    /// Signing error
84    #[error(transparent)]
85    SigningError(#[from] SignatureError),
86
87    /// Client was constructed with without a signer
88    #[error("Client was constructed with without a signer")]
89    MissingSigner,
90
91    /// Error related to the metadata
92    #[error(transparent)]
93    Metadata(#[from] MetadataError),
94
95    /// Couldn't parse expected sequence from the error message
96    #[error("Couldn't parse expected sequence from: '{0}'")]
97    SequenceParsingFailed(String),
98}
99
100/// Representation of all the errors that can occur when building [`GrpcClient`] using
101/// [`GrpcClientBuilder`]
102///
103/// [`GrpcClient`]: crate::GrpcClient
104/// [`GrpcClientBuilder`]: crate::GrpcClientBuilder
105#[derive(Debug, thiserror::Error)]
106pub enum GrpcClientBuilderError {
107    /// Error from tonic transport
108    #[error(transparent)]
109    #[cfg(not(target_arch = "wasm32"))]
110    TonicTransportError(#[from] tonic::transport::Error),
111
112    /// Transport has not been set for builder
113    #[error("Transport not set")]
114    TransportNotSet,
115
116    /// Invalid private key.
117    #[error("Invalid private key")]
118    InvalidPrivateKey,
119
120    /// Invalid public key.
121    #[error("Invalid public key")]
122    InvalidPublicKey,
123
124    /// Error related to the metadata
125    #[error(transparent)]
126    Metadata(#[from] MetadataError),
127
128    /// Tls support is not enabled but requested
129    #[error(
130        "Tls support is not enabled but requested via url, please enable it using proper feature flags"
131    )]
132    TlsNotSupported,
133}
134
135#[derive(thiserror::Error, Debug)]
136pub enum MetadataError {
137    /// Invalid metadata key
138    #[error("Invalid metadata key ({0})")]
139    Key(String),
140
141    /// Invalid binary metadata key
142    #[error("Invalid binary metadata key ({0:?})")]
143    KeyBin(Vec<u8>),
144
145    /// Invalid metadata value for given key
146    #[error("Invalid metadata value (key: {0:?})")]
147    Value(String),
148}
149
150impl From<Status> for Error {
151    fn from(value: Status) -> Self {
152        Error::TonicError(Box::new(value))
153    }
154}
155
156#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
157impl From<Error> for wasm_bindgen::JsValue {
158    fn from(error: Error) -> wasm_bindgen::JsValue {
159        error.to_string().into()
160    }
161}
162
163#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
164impl From<GrpcClientBuilderError> for wasm_bindgen::JsValue {
165    fn from(error: GrpcClientBuilderError) -> wasm_bindgen::JsValue {
166        error.to_string().into()
167    }
168}