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
8pub type Result<T, E = Error> = std::result::Result<T, E>;
12
13#[derive(Debug, thiserror::Error)]
17pub enum Error {
18 #[error(transparent)]
20 TonicError(Box<Status>),
21
22 #[cfg(not(target_arch = "wasm32"))]
24 #[error("Transport: {0}")]
25 TransportError(#[from] tonic::transport::Error),
26
27 #[error(transparent)]
29 TendermintError(#[from] tendermint::Error),
30
31 #[error(transparent)]
33 CelestiaTypesError(#[from] celestia_types::Error),
34
35 #[error(transparent)]
37 TendermintProtoError(#[from] tendermint_proto::Error),
38
39 #[error("Failed to parse response")]
41 FailedToParseResponse,
42
43 #[error("Unexpected response type")]
45 UnexpectedResponseType(String),
46
47 #[error("Attempted to submit blob transaction with empty blob list")]
49 TxEmptyBlobList,
50
51 #[error("Broadcasting transaction {0} failed; code: {1}, error: {2}")]
53 TxBroadcastFailed(Hash, ErrorCode, String),
54
55 #[error("Transaction {0} execution failed; code: {1}, error: {2}")]
57 TxExecutionFailed(Hash, ErrorCode, String),
58
59 #[error("Transaction {0} was rejected; code: {1}, error: {2}")]
61 TxRejected(Hash, ErrorCode, String),
62
63 #[error("Transaction {0} was evicted from the mempool")]
65 TxEvicted(Hash),
66
67 #[error("Transaction {0} wasn't found, it was likely rejected")]
69 TxNotFound(Hash),
70
71 #[error("Provided public key differs from one associated with account")]
73 PublicKeyMismatch,
74
75 #[error("ABCI proof verification has failed: {0}")]
77 AbciProof(#[from] ProofError),
78
79 #[error("ABCI query returned an error (code {0}): {1}")]
81 AbciQuery(ErrorCode, String),
82
83 #[error(transparent)]
85 SigningError(#[from] SignatureError),
86
87 #[error("Client was constructed with without a signer")]
89 MissingSigner,
90
91 #[error(transparent)]
93 Metadata(#[from] MetadataError),
94
95 #[error("Couldn't parse expected sequence from: '{0}'")]
97 SequenceParsingFailed(String),
98}
99
100#[derive(Debug, thiserror::Error)]
106pub enum GrpcClientBuilderError {
107 #[error(transparent)]
109 #[cfg(not(target_arch = "wasm32"))]
110 TonicTransportError(#[from] tonic::transport::Error),
111
112 #[error("Transport not set")]
114 TransportNotSet,
115
116 #[error("Invalid private key")]
118 InvalidPrivateKey,
119
120 #[error("Invalid public key")]
122 InvalidPublicKey,
123
124 #[error(transparent)]
126 Metadata(#[from] MetadataError),
127
128 #[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 #[error("Invalid metadata key ({0})")]
139 Key(String),
140
141 #[error("Invalid binary metadata key ({0:?})")]
143 KeyBin(Vec<u8>),
144
145 #[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}