gevulot_rs/
error.rs

1use cosmrs::ErrorReport;
2use hex::FromHexError;
3use prost::{DecodeError, EncodeError};
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("missing event attribute: {0}")]
8    MissingEventAttribute(&'static str),
9    #[error("invalid event attribute: {0}")]
10    InvalidEventAttribute(&'static str),
11    #[error("unknown event kind: {0}")]
12    UnknownEventKind(String),
13    #[error("rpc connection error: {0}")]
14    RpcConnectionError(String),
15    #[error("decode error: {0}")]
16    DecodeError(String),
17    #[error("encode error: {0}")]
18    EncodeError(String),
19    #[error("not found")]
20    NotFound,
21    #[error("parse error: {0}")]
22    Parse(String),
23    #[error("tendermint error: {0}")]
24    Tendermint(#[from] tendermint::Error),
25    #[error("tx {0} failed with code {1}: {2}")]
26    Tx(String, u32, String),
27    #[error("unknown error: {0}")]
28    Unknown(String),
29}
30
31pub type Result<T> = std::result::Result<T, Error>;
32
33impl From<Box<dyn std::error::Error>> for Error {
34    fn from(error: Box<dyn std::error::Error>) -> Self {
35        Error::Unknown(error.to_string())
36    }
37}
38
39impl From<EncodeError> for Error {
40    fn from(error: EncodeError) -> Self {
41        Error::EncodeError(error.to_string())
42    }
43}
44
45impl From<cosmrs::rpc::error::Error> for Error {
46    fn from(error: cosmrs::rpc::error::Error) -> Self {
47        Error::RpcConnectionError(error.to_string())
48    }
49}
50
51impl From<tonic::Status> for Error {
52    fn from(error: tonic::Status) -> Self {
53        Error::RpcConnectionError(error.to_string())
54    }
55}
56
57impl From<http::uri::InvalidUri> for Error {
58    fn from(error: http::uri::InvalidUri) -> Self {
59        Error::RpcConnectionError(error.to_string())
60    }
61}
62
63impl From<DecodeError> for Error {
64    fn from(error: DecodeError) -> Self {
65        Error::DecodeError(error.to_string())
66    }
67}
68
69impl From<tonic::transport::Error> for Error {
70    fn from(error: tonic::transport::Error) -> Self {
71        Error::RpcConnectionError(error.to_string())
72    }
73}
74
75impl From<bip32::Error> for Error {
76    fn from(error: bip32::Error) -> Self {
77        Error::Parse(error.to_string())
78    }
79}
80
81impl From<ErrorReport> for Error {
82    fn from(error: ErrorReport) -> Self {
83        Error::Unknown(error.to_string())
84    }
85}
86
87impl From<FromHexError> for Error {
88    fn from(error: FromHexError) -> Self {
89        Error::Parse(error.to_string())
90    }
91}
92
93impl From<&str> for Error {
94    fn from(error: &str) -> Self {
95        Error::Unknown(error.to_string())
96    }
97}