cosm_tome_wasm_deploy_fork/chain/
error.rs1use cosmrs::proto::prost::{DecodeError, EncodeError};
2use cosmrs::ErrorReport;
3use thiserror::Error;
4
5#[cfg(feature = "os_keyring")]
6pub use keyring::Error as KeyringError;
7
8pub use cosmrs::rpc::Error as TendermintRPCError;
9pub use cosmrs::tendermint::Error as TendermintError;
10pub use tonic::transport::Error as CosmosGRPCError;
11
12use super::response::ChainResponse;
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("invalid cosmos msg sent to simulate endpoint")]
44 Simulation,
45
46 #[cfg(feature = "os_keyring")]
47 #[error(transparent)]
48 Keyring(#[from] KeyringError),
49
50 #[error("CosmosSDK error: {res:?}")]
51 CosmosSdk { res: ChainResponse },
52
53 #[error("Tendermint error")]
54 Tendermint(#[from] TendermintError),
55
56 #[error(transparent)]
58 RPC(#[from] TendermintRPCError),
59
60 #[error(transparent)]
62 GRPC(#[from] CosmosGRPCError),
63}
64
65impl ChainError {
66 pub(crate) fn crypto(e: ErrorReport) -> ChainError {
67 ChainError::Crypto {
68 message: e.to_string(),
69 }
70 }
71
72 pub(crate) fn proto_encoding(e: ErrorReport) -> ChainError {
73 ChainError::ProtoEncoding {
74 message: e.to_string(),
75 }
76 }
77
78 pub(crate) fn prost_proto_encoding(e: EncodeError) -> ChainError {
79 ChainError::ProtoEncoding {
80 message: e.to_string(),
81 }
82 }
83
84 pub(crate) fn prost_proto_decoding(e: DecodeError) -> ChainError {
85 ChainError::ProtoDecoding {
86 message: e.to_string(),
87 }
88 }
89
90 pub(crate) fn tonic_status(e: tonic::Status) -> ChainError {
91 ChainError::CosmosSdk { res: e.into() }
92 }
93}
94
95#[derive(Error, Debug)]
96pub enum DeserializeError {
97 #[error("Raw chain response is empty")]
98 EmptyResponse,
99
100 #[error(transparent)]
101 Serde(#[from] serde_json::error::Error),
102}