cosmos_gravity_utils/
error.rs1use clarity::Error as ClarityError;
5use deep_space::error::AddressError as CosmosAddressError;
6use deep_space::error::CosmosGrpcError;
7use num_bigint::ParseBigIntError;
8use std::fmt::{self, Debug};
9use tokio::time::error::Elapsed;
10use tonic::Status;
11use web30::jsonrpc::error::Web3Error;
12
13#[derive(Debug)]
14#[allow(clippy::large_enum_variant)]
15pub enum GravityError {
16 InvalidBigInt(ParseBigIntError),
17 CosmosGrpcError(CosmosGrpcError),
18 CosmosAddressError(CosmosAddressError),
19 EthereumRestError(Web3Error),
20 InvalidBridgeStateError(String),
21 FailedToUpdateValset,
22 EthereumContractError(String),
23 InvalidOptionsError(String),
24 ClarityError(ClarityError),
25 TimeoutError,
26 InvalidEventLogError(String),
27 GravityGrpcError(Status),
28 InsufficientVotingPowerToPass(String),
29 ParseBigIntError(ParseBigIntError),
30}
31
32impl fmt::Display for GravityError {
33 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34 match self {
35 GravityError::GravityGrpcError(val) => write!(f, "Gravity gRPC error {}", val),
36 GravityError::CosmosGrpcError(val) => write!(f, "Cosmos gRPC error {}", val),
37 GravityError::InvalidBigInt(val) => {
38 write!(f, "Got invalid BigInt from cosmos! {}", val)
39 }
40 GravityError::CosmosAddressError(val) => write!(f, "Cosmos Address error {}", val),
41 GravityError::EthereumRestError(val) => write!(f, "Ethereum REST error {}", val),
42 GravityError::InvalidOptionsError(val) => {
43 write!(f, "Invalid TX options for this call {}", val)
44 }
45 GravityError::InvalidBridgeStateError(val) => {
46 write!(f, "Invalid bridge state! {}", val)
47 }
48 GravityError::FailedToUpdateValset => write!(f, "ValidatorSetUpdate Failed!"),
49 GravityError::TimeoutError => write!(f, "Operation timed out!"),
50 GravityError::ClarityError(val) => write!(f, "Clarity Error {}", val),
51 GravityError::InvalidEventLogError(val) => write!(f, "InvalidEvent: {}", val),
52 GravityError::EthereumContractError(val) => {
53 write!(f, "Contract operation failed: {}", val)
54 }
55 GravityError::InsufficientVotingPowerToPass(val) => {
56 write!(f, "{}", val)
57 }
58 GravityError::ParseBigIntError(val) => write!(f, "Failed to parse big integer {}", val),
59 }
60 }
61}
62
63impl std::error::Error for GravityError {}
64
65impl From<CosmosGrpcError> for GravityError {
66 fn from(error: CosmosGrpcError) -> Self {
67 GravityError::CosmosGrpcError(error)
68 }
69}
70
71impl From<Elapsed> for GravityError {
72 fn from(_error: Elapsed) -> Self {
73 GravityError::TimeoutError
74 }
75}
76
77impl From<ClarityError> for GravityError {
78 fn from(error: ClarityError) -> Self {
79 GravityError::ClarityError(error)
80 }
81}
82
83impl From<Web3Error> for GravityError {
84 fn from(error: Web3Error) -> Self {
85 GravityError::EthereumRestError(error)
86 }
87}
88impl From<Status> for GravityError {
89 fn from(error: Status) -> Self {
90 GravityError::GravityGrpcError(error)
91 }
92}
93impl From<CosmosAddressError> for GravityError {
94 fn from(error: CosmosAddressError) -> Self {
95 GravityError::CosmosAddressError(error)
96 }
97}
98impl From<ParseBigIntError> for GravityError {
99 fn from(error: ParseBigIntError) -> Self {
100 GravityError::InvalidBigInt(error)
101 }
102}