1use alloc::string::{String, ToString};
2
3use displaydoc::Display;
4use ibc::core::channel::types::error::ChannelError;
5use ibc::core::client::types::error::ClientError;
6use ibc::core::connection::types::error::ConnectionError;
7use ibc::core::handler::types::error::HandlerError;
8use ibc::core::host::types::error::{DecodingError, HostError, IdentifierError};
9use tonic::Status;
10
11#[derive(Debug, Display)]
15pub enum QueryError {
16 Handler(HandlerError),
18 Host(HostError),
20 Decoding(DecodingError),
22 MissingProof(String),
24 MissingField(String),
26}
27
28impl QueryError {
29 pub fn missing_proof<T: ToString>(description: T) -> Self {
30 Self::MissingProof(description.to_string())
31 }
32
33 pub fn missing_field<T: ToString>(description: T) -> Self {
34 Self::MissingField(description.to_string())
35 }
36}
37
38impl From<QueryError> for Status {
39 fn from(e: QueryError) -> Self {
40 match e {
41 QueryError::Handler(ctx_err) => Self::internal(ctx_err.to_string()),
42 QueryError::Host(host_err) => Self::internal(host_err.to_string()),
43 QueryError::Decoding(de) => Self::internal(de.to_string()),
44 QueryError::MissingProof(description) => Self::not_found(description),
45 QueryError::MissingField(description) => Self::invalid_argument(description),
46 }
47 }
48}
49
50impl From<ClientError> for QueryError {
51 fn from(e: ClientError) -> Self {
52 Self::Handler(HandlerError::Client(e))
53 }
54}
55
56impl From<ConnectionError> for QueryError {
57 fn from(e: ConnectionError) -> Self {
58 Self::Handler(HandlerError::Connection(e))
59 }
60}
61
62impl From<ChannelError> for QueryError {
63 fn from(e: ChannelError) -> Self {
64 Self::Handler(HandlerError::Channel(e))
65 }
66}
67
68impl From<DecodingError> for QueryError {
69 fn from(e: DecodingError) -> Self {
70 Self::Decoding(e)
71 }
72}
73
74impl From<IdentifierError> for QueryError {
75 fn from(e: IdentifierError) -> Self {
76 Self::Decoding(DecodingError::Identifier(e))
77 }
78}
79
80impl From<HostError> for QueryError {
81 fn from(e: HostError) -> Self {
82 Self::Host(e)
83 }
84}