cosm_utils/chain/
error.rs1use cosmrs::proto::cosmos::base::abci::v1beta1::Result;
2use cosmrs::proto::prost::{DecodeError, EncodeError};
3use cosmrs::tendermint::Hash;
4use cosmrs::ErrorReport;
5use tendermint_rpc::endpoint::abci_query::AbciQuery;
6use thiserror::Error;
7
8#[cfg(feature = "keyring")]
9pub use keyring::Error as KeyringError;
10
11pub use cosmrs::rpc::Error as TendermintRPCError;
12pub use cosmrs::tendermint::Error as TendermintError;
13
14#[derive(Error, Debug)]
15pub enum ChainError {
16 #[error("invalid denomination: {name:?}")]
17 Denom { name: String },
18
19 #[error("invalid chainId: {chain_id:?}")]
20 ChainId { chain_id: String },
21
22 #[error("api endpoint is not configured {api_type:?}")]
23 MissingApiEndpoint { api_type: String },
24
25 #[error("invalid mnemonic")]
26 Mnemonic,
27
28 #[error("invalid derivation path")]
29 DerviationPath,
30
31 #[error("cryptographic error: {message:?}")]
32 Crypto { message: String },
33
34 #[error("invalid query path url: {url:?}")]
35 QueryPath { url: String },
36
37 #[error("proto encoding error: {message:?}")]
38 ProtoEncoding { message: String },
39
40 #[error("proto decoding error: {message:?}")]
41 ProtoDecoding { message: String },
42
43 #[error("error during simulation: {result:?}")]
44 Simulation { result: Result },
45
46 #[error("tx_search timed out looking for: {tx_hash:?}")]
47 TxSearchTimeout { tx_hash: Hash },
48
49 #[error("tx_commit error: {res}")]
50 TxCommit { res: String },
51
52 #[error("tx_sync error: {res}")]
53 TxSync { res: String },
54
55 #[error("tx_async error: {res}")]
56 TxAsync { res: String },
57
58 #[cfg(feature = "keyring")]
59 #[error(transparent)]
60 Keyring(#[from] KeyringError),
61
62 #[error("CosmosSDK error: {res:?}")]
63 AbciQuery { res: AbciQuery },
64
65 #[error("Tendermint error")]
66 Tendermint(#[from] TendermintError),
67
68 #[error(transparent)]
69 RPC(#[from] TendermintRPCError),
70}
71
72impl ChainError {
73 pub(crate) fn crypto(e: ErrorReport) -> ChainError {
74 ChainError::Crypto {
75 message: e.to_string(),
76 }
77 }
78
79 pub(crate) fn proto_encoding(e: ErrorReport) -> ChainError {
80 ChainError::ProtoEncoding {
81 message: e.to_string(),
82 }
83 }
84
85 pub(crate) fn prost_proto_encoding(e: EncodeError) -> ChainError {
86 ChainError::ProtoEncoding {
87 message: e.to_string(),
88 }
89 }
90
91 pub(crate) fn prost_proto_decoding(e: DecodeError) -> ChainError {
92 ChainError::ProtoDecoding {
93 message: e.to_string(),
94 }
95 }
96}
97
98#[derive(Error, Debug)]
99pub enum DeserializeError {
100 #[error("Raw chain response is empty")]
101 EmptyResponse,
102
103 #[error(transparent)]
104 Serde(#[from] serde_json::error::Error),
105}