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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
use std::{num::ParseIntError, str::ParseBoolError};
use base16::DecodeError;
use humantime::{DurationError, TimestampError};
use thiserror::Error;
#[cfg(doc)]
use casper_types::{
account::AccountHash, Key, NamedArg, PublicKey, RuntimeArgs, TimeDiff, Timestamp, URef,
};
use casper_types::{CLValueError, KeyFromStrError, UIntParseError, URefFromStrError};
pub use uint::FromDecStrErr;
use crate::cli::JsonArgsError;
#[cfg(doc)]
use crate::rpcs::DictionaryItemIdentifier;
/// Error that can be returned by the `cli` API.
#[derive(Error, Debug)]
pub enum CliError {
/// Failed to parse a [`Key`] from a formatted string.
#[error("failed to parse {context} as a key: {error}")]
FailedToParseKey {
/// Contextual description of where this error occurred.
context: &'static str,
/// The actual error raised.
error: KeyFromStrError,
},
/// Failed to parse a [`PublicKey`] from a formatted string.
#[error("failed to parse {context} as a public key: {error}")]
FailedToParsePublicKey {
/// Contextual description of where this error occurred.
context: String,
/// The actual error raised.
error: casper_types::crypto::Error,
},
/// Failed to parse an [`AccountHash`] from a formatted string.
#[error("failed to parse {context} as an account hash: {error}")]
FailedToParseAccountHash {
/// Contextual description of where this error occurred.
context: &'static str,
/// The actual error raised.
error: casper_types::addressable_entity::FromStrError,
},
/// Failed to parse an [`casper_types::AddressableEntityHash`] from a formatted string.
#[error("failed to parse {context} as an addressable entity hash: {error}")]
FailedToParseAddressableEntityHash {
/// Contextual description of where this error occurred.
context: &'static str,
/// The actual error raised.
error: casper_types::addressable_entity::FromStrError,
},
/// Failed to parse a [`URef`] from a formatted string.
#[error("failed to parse '{context}' as a uref: {error}")]
FailedToParseURef {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: URefFromStrError,
},
/// Failed to parse an integer from a string.
#[error("failed to parse '{context}' as an integer: {error}")]
FailedToParseInt {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: ParseIntError,
},
/// Failed to parse a bool from a string.
#[error("failed to parse '{context}' as a bool: {error}")]
FailedToParseBool {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: ParseBoolError,
},
/// Failed to parse an integer from a string.
#[error("failed to parse '{context}' as an integer: {error}")]
FailedToParseDec {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: FromDecStrErr,
},
/// Failed to parse a [`TimeDiff`] from a formatted string.
#[error("failed to parse '{context}' as a time diff: {error}")]
FailedToParseTimeDiff {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: DurationError,
},
/// Failed to parse a [`Timestamp`] from a formatted string.
#[error("failed to parse '{context}' as a timestamp: {error}")]
FailedToParseTimestamp {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: TimestampError,
},
/// Failed to parse a `U128`, `U256` or `U512` from a string.
#[error("failed to parse '{context}' as u128, u256, or u512: {error:?}")]
FailedToParseUint {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: UIntParseError,
},
/// Failed to parse a `Digest` from a string.
#[error("failed to parse '{context}' as a hash digest: {error:?}")]
FailedToParseDigest {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// The actual error raised.
error: casper_types::DigestError,
},
/// Failed to create a [`GlobalStateIdentifier`].
#[error("failed to parse state identifier")]
FailedToParseStateIdentifier,
/// Conflicting arguments.
#[error("conflicting arguments passed '{context}' {args:?}")]
ConflictingArguments {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: String,
/// Arguments passed, with their values.
args: Vec<String>,
},
/// Invalid `CLValue`.
#[error("invalid CLValue error: {0}")]
InvalidCLValue(String),
/// Invalid argument.
#[error("invalid argument '{context}': {error}")]
InvalidArgument {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// An error message.
error: String,
},
/// Error while parsing the json-args from a string to JSON.
#[error(
"failed to parse json-args to JSON: {0}. They should be a JSON Array of Objects, each of \
the form {{\"name\":<String>,\"type\":<VALUE>,\"value\":<VALUE>}}"
)]
FailedToParseJsonArgs(#[from] serde_json::Error),
/// Error while building a [`NamedArg`] from parsed JSON input.
#[error(transparent)]
JsonArgs(#[from] JsonArgsError),
/// Core error.
#[error(transparent)]
Core(#[from] crate::Error),
/// Failed to parse a package address
#[error("Failed to parse a package address")]
FailedToParsePackageAddr,
/// Failed to parse a transfer target
#[error("Failed to parse a transfer target")]
FailedToParseTransferTarget,
/// Failed to parse a validator public key.
#[error("Failed to parse a validator public key")]
FailedToParseValidatorPublicKey,
/// Failed to parse base16 bytes.
#[error("Failed to parse base16 bytes: {0}")]
FailedToParseBase16(#[from] DecodeError),
/// Unexpected transaction args variant.
#[error("Unexpected transaction args variant")]
UnexpectedTransactionArgsVariant,
/// Failed to get auction info to determine validator stake.
#[error("Failed to get auction state")]
FailedToGetAuctionState,
/// Attempting to withdraw bid will reduce stake below the minimum amount.
#[error("Attempting to withdraw bid will reduce stake below the minimum amount.")]
ReducedStakeBelowMinAmount,
/// Failed to parse the chainspec as raw bytes.
#[error("Failed to parse the chainspec as raw bytes")]
FailedToParseChainspecBytes,
/// Missing major version.
#[error("Major version is missing when specifying entity version")]
MissingMajorVersion,
/// Failed to get system hash registry
#[error("Failed to retrieve system hash registry")]
FailedToGetSystemHashRegistry,
/// Failed to get auction hash.
#[error("Missing auction hash")]
MissingAuctionHash,
/// Failed to get state root hash
#[error("Failed to retrieve state root hash")]
FailedToGetStateRootHash,
/// Failed to parse the transaction target.
#[error("Failed to parse the transaction target: {0}")]
FailedToParseTransactionPayloadField(String),
/// Unexpected Stored value
#[error("unexpected stored value")]
UnexpectedStoredValue,
}
impl From<CLValueError> for CliError {
fn from(error: CLValueError) -> Self {
match error {
CLValueError::Serialization(bytesrepr_error) => CliError::Core(bytesrepr_error.into()),
CLValueError::Type(type_mismatch) => {
CliError::InvalidCLValue(type_mismatch.to_string())
}
}
}
}