test_tube_prov/runner/
error.rs1use cosmrs::rpc::error::Error as TendermintRpcError;
2use cosmrs::tendermint::Error as TendermintError;
3use cosmrs::ErrorReport;
4use std::str::Utf8Error;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum RunnerError {
9 #[error("unable to encode request")]
10 EncodeError(#[from] EncodeError),
11
12 #[error("unable to decode response")]
13 DecodeError(#[from] DecodeError),
14
15 #[error("query error: {}", .msg)]
16 QueryError { msg: String },
17
18 #[error("execute error: {}", .msg)]
19 ExecuteError { msg: String },
20
21 #[error("{0}")]
22 GenericError(String),
23
24 #[error("{0}")]
25 ErrorReport(#[from] ErrorReport),
26
27 #[error("{0}")]
28 Tendermint(#[from] TendermintError),
29
30 #[error("{0}")]
31 TendermintRpc(#[from] TendermintRpcError),
32}
33
34impl PartialEq for RunnerError {
35 fn eq(&self, other: &Self) -> bool {
36 match (self, other) {
37 (RunnerError::EncodeError(a), RunnerError::EncodeError(b)) => a == b,
38 (RunnerError::DecodeError(a), RunnerError::DecodeError(b)) => a == b,
39 (RunnerError::QueryError { msg: a }, RunnerError::QueryError { msg: b }) => a == b,
40 (RunnerError::ExecuteError { msg: a }, RunnerError::ExecuteError { msg: b }) => a == b,
41 (RunnerError::ErrorReport(a), RunnerError::ErrorReport(b)) => {
42 a.to_string() == b.to_string()
43 }
44 (RunnerError::Tendermint(a), RunnerError::Tendermint(b)) => {
45 a.to_string() == b.to_string()
46 }
47 (RunnerError::TendermintRpc(a), RunnerError::TendermintRpc(b)) => a.0 == b.0,
48 _ => false,
49 }
50 }
51}
52
53#[derive(Error, Debug)]
54pub enum DecodeError {
55 #[error("{0}")]
56 GenericError(String),
57
58 #[error("invalid utf8 bytes")]
59 Utf8Error(#[from] Utf8Error),
60
61 #[error("invalid protobuf")]
62 ProtoDecodeError(#[from] prost::DecodeError),
63
64 #[error("invalid json")]
65 JsonDecodeError(#[from] serde_json::Error),
66
67 #[error("invalid base64")]
68 Base64DecodeError(#[from] base64::DecodeError),
69
70 #[error("invalid signing key")]
71 SigningKeyDecodeError { msg: String },
72}
73
74impl PartialEq for DecodeError {
75 fn eq(&self, other: &Self) -> bool {
76 match (self, other) {
77 (DecodeError::Utf8Error(a), DecodeError::Utf8Error(b)) => a == b,
78 (DecodeError::ProtoDecodeError(a), DecodeError::ProtoDecodeError(b)) => a == b,
79 (DecodeError::JsonDecodeError(a), DecodeError::JsonDecodeError(b)) => {
80 a.to_string() == b.to_string()
81 }
82 (DecodeError::Base64DecodeError(a), DecodeError::Base64DecodeError(b)) => a == b,
83 (
84 DecodeError::SigningKeyDecodeError { msg: a },
85 DecodeError::SigningKeyDecodeError { msg: b },
86 ) => a == b,
87 _ => false,
88 }
89 }
90}
91
92#[derive(Error, Debug)]
93pub enum EncodeError {
94 #[error("invalid protobuf")]
95 ProtoEncodeError(#[from] prost::EncodeError),
96
97 #[error("unable to encode json")]
98 JsonEncodeError(#[from] serde_json::Error),
99}
100
101impl PartialEq for EncodeError {
102 fn eq(&self, other: &Self) -> bool {
103 match (self, other) {
104 (EncodeError::ProtoEncodeError(a), EncodeError::ProtoEncodeError(b)) => a == b,
105 (EncodeError::JsonEncodeError(a), EncodeError::JsonEncodeError(b)) => {
106 a.to_string() == b.to_string()
107 }
108 _ => false,
109 }
110 }
111}