forked from icon-project/IBC-Integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
101 lines (90 loc) · 3.56 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
use cosmwasm_std::StdError;
use cw_common::errors::CwErrors;
use prost::DecodeError;
use thiserror::Error;
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
#[error("Unauthorized")]
Unauthorized {},
// Add any other custom errors you like here.
// Look at https://docs.rs/thiserror/1.0.21/thiserror/ for details.
#[error("{0}")]
DecodeError(#[from] DecodeError),
#[error("Timestamp not found for {client_id:?} at height {height:?}")]
TimestampNotFound { height: u64, client_id: String },
#[error("Client state not found for client_id:{0}")]
ClientStateNotFound(String),
#[error("Height not found in client state for client_id:{0}")]
HeightNotSaved(String),
#[error("Consensusstate not found for {client_id:?} at height {height:?}")]
ConsensusStateNotFound { height: u64, client_id: String },
#[error("Failed to save client state")]
FailedToSaveClientState,
#[error("Failed to save consensus state")]
FailedToSaveConsensusState,
#[error("Insufficient validator signatures supplied")]
InSuffcientQuorum,
#[error("Clientstate already exists for {0}")]
ClientStateAlreadyExists(String),
#[error("Config not found or initialized")]
ConfigNotFound,
#[error("Trusting Period elapsed. Height: {update_height:?} trusted height is at {trusted_height:?}")]
TrustingPeriodElapsed {
trusted_height: u64,
update_height: u64,
},
#[error("Invalid header update {0}")]
InvalidHeaderUpdate(String),
#[error("Invalid message root {0}")]
InvalidMessageRoot(String),
#[error("Failed to save processed time")]
FailedToSaveProcessedTime,
#[error("Processed time not found for {client_id:?} at height {height:?}")]
ProcessedTimeNotFound { client_id: String, height: u64 },
#[error("Processed height not found for {client_id:?} at height {height:?}")]
ProcessedHeightNotFound { client_id: String, height: u64 },
#[error("Too early to process by time elapsed")]
NotEnoughtTimeElapsed,
#[error("Too early to process by block elapsed")]
NotEnoughtBlocksElapsed,
#[error("Failed to init contract")]
FailedToInitContract,
#[error("Failed to save config")]
FailedToSaveConfig,
#[error("Client state frozen at {0}")]
ClientStateFrozen(u64),
#[error("Failed Parsing Height {0}")]
FailedToParseHeight(String),
#[error("Invalid Client Id {0}")]
InvalidClientId(String),
#[error("Failed To Create ClientId")]
FailedToCreateClientId(String),
#[error("FailedConvertingToBinary")]
FailedConvertingToBinary,
#[error("InvalidHeight")]
InvalidHeight,
#[error("InvalidProofContextHash")]
InvalidProofContextHash,
#[error("UpdateBlockOlderThanTrustedHeight")]
UpdateBlockOlderThanTrustedHeight,
#[error("UpdateBlockTooOld")]
UpdateBlockTooOld,
#[error("Height {height:?} already updated ")]
HeightAlreadyUpdated { height: u64 },
}
impl From<CwErrors> for ContractError {
fn from(value: CwErrors) -> Self {
match value {
CwErrors::FailedToCreateClientId {
client_type: _,
counter: _,
validation_error,
} => ContractError::FailedToCreateClientId(validation_error.to_string()),
CwErrors::InvalidClientId(e, _err) => ContractError::InvalidClientId(e),
CwErrors::DecodeError { error } => ContractError::DecodeError(DecodeError::new(error)),
CwErrors::FailedToConvertToPacketDataResponse(e) => ContractError::Std(e),
}
}
}