forked from icon-project/IBC-Integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
155 lines (126 loc) · 5.24 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use common::ibc::core::ics03_connection::error::ConnectionError;
use cw_common::errors::CwErrors;
use hex::FromHexError;
use prost::DecodeError;
use super::*;
#[derive(Error, Debug)]
/// This code defines an error enum called `ContractError` that represents various errors that can occur
/// in a contract. Each variant of the enum represents a different type of error and includes additional
/// information about the error, such as an error message or an error code. The `#[error]` attribute is
/// used to specify the format of the error message for each variant. Some variants also include
/// associated data, such as a `String` for the `InvalidClientId` variant or a `PortError` for the
/// `IbcPortError` variant. The `#[from]` attribute is used to automatically convert errors of the
/// specified type into the `StdError` variant of `ContractError`.
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
#[error("Unauthorized")]
Unauthorized {},
#[error("InvalidCommitmentKey")]
InvalidCommitmentKey,
#[error("InvalidConnectiontId {connection_id}")]
InvalidConnectiontId { connection_id: String },
#[error("InvalidClientId {client_id}")]
InvalidClientId { client_id: String },
#[error("InvalidClientType {client_type}")]
InvalidClientType { client_type: String },
#[error("InvalidNextClientSequence")]
InvalidNextClientSequence {},
#[error("IbcContextError {error}")]
IbcContextError { error: String },
#[error("IbcDecodeError {error}")]
IbcDecodeError { error: DecodeError },
#[error("IbcPortError {error}")]
IbcPortError { error: PortError },
#[error("IbcPacketError {error}")]
IbcPacketError { error: PacketError },
#[error("IbcChannelError {error}")]
IbcChannelError { error: ChannelError },
#[error("IbcConnectionError {error}")]
IbcConnectionError { error: ConnectionError },
#[error("IbcClientError {error}")]
IbcClientError { error: ClientError },
#[error("IbcValidationError {error}")]
IbcValidationError { error: ValidationError },
#[error("ERR_REPLY_ERROR|{code:?}|{msg:?}")]
ReplyError { code: u64, msg: String },
#[error("InsufficientBalance")]
InsufficientBalance {},
#[error("IbcDecodeError {error}")]
IbcRawConversionError { error: String },
#[error("FailedConversion")]
FailedConversion,
#[error("Light Client Validation failed for {0}")]
LightClientValidationFailed(String),
#[error("Invalid EventType in {event} {event_type}")]
InvalidEventType { event: String, event_type: String },
}
impl From<FromHexError> for ContractError {
fn from(value: FromHexError) -> Self {
ContractError::IbcDecodeError {
error: DecodeError::new(value.to_string()), // "Hex String Decode Failed".to_owned(),
}
}
}
impl From<prost::DecodeError> for ContractError {
fn from(value: prost::DecodeError) -> Self {
ContractError::IbcDecodeError {
error: value, // "Decode Failed".to_owned(),
}
}
}
/// This code defines an implementation of the `From` trait for the `ContractError` enum, which allows
/// instances of the `CwErrors` enum to be converted into instances of the `ContractError` enum. The
/// implementation matches on the different variants of the `CwErrors` enum and constructs an
/// appropriate variant of the `ContractError` enum based on the error information contained in the
/// `CwErrors` variant. For example, if the `CwErrors` variant is `FailedToCreateClientId`, the
/// implementation constructs an `IbcClientError` variant of the `ContractError` enum with a
/// `ClientIdentifierConstructor` error from the `common::ibc::core::ics02_client::error::ClientError` enum.
impl From<CwErrors> for ContractError {
fn from(value: CwErrors) -> Self {
match value {
CwErrors::FailedToCreateClientId {
client_type: _,
counter: _,
validation_error,
} => Self::IbcValidationError {
error: validation_error,
},
CwErrors::InvalidClientId(_client_id, err) => Self::IbcValidationError { error: err },
CwErrors::DecodeError { error } => Self::IbcDecodeError {
error: DecodeError::new(error),
},
CwErrors::FailedToConvertToPacketDataResponse(_) => Self::FailedConversion,
}
}
}
impl From<ChannelError> for ContractError {
fn from(value: ChannelError) -> Self {
ContractError::IbcChannelError { error: value }
}
}
impl From<PacketError> for ContractError {
fn from(value: PacketError) -> Self {
ContractError::IbcPacketError { error: value }
}
}
impl From<ConnectionError> for ContractError {
fn from(value: ConnectionError) -> Self {
ContractError::IbcConnectionError { error: value }
}
}
impl From<PortError> for ContractError {
fn from(value: PortError) -> Self {
ContractError::IbcPortError { error: value }
}
}
impl From<ValidationError> for ContractError {
fn from(value: ValidationError) -> Self {
ContractError::IbcValidationError { error: value }
}
}
impl From<ClientError> for ContractError {
fn from(value: ClientError) -> Self {
ContractError::IbcClientError { error: value }
}
}