casper_client/cli/
error.rs1use std::{num::ParseIntError, str::ParseBoolError};
2
3use base16::DecodeError;
4use humantime::{DurationError, TimestampError};
5use thiserror::Error;
6
7#[cfg(doc)]
8use casper_types::{
9 account::AccountHash, Key, NamedArg, PublicKey, RuntimeArgs, TimeDiff, Timestamp, URef,
10};
11use casper_types::{CLValueError, KeyFromStrError, UIntParseError, URefFromStrError};
12pub use uint::FromDecStrErr;
13
14use crate::cli::JsonArgsError;
15#[cfg(doc)]
16use crate::rpcs::{DictionaryItemIdentifier, GlobalStateIdentifier};
17
18#[derive(Error, Debug)]
20pub enum CliError {
21 #[error("failed to parse {context} as a key: {error}")]
23 FailedToParseKey {
24 context: &'static str,
26 error: KeyFromStrError,
28 },
29
30 #[error("failed to parse {context} as a public key: {error}")]
32 FailedToParsePublicKey {
33 context: String,
35 error: casper_types::crypto::Error,
37 },
38
39 #[error("failed to parse {context} as an account hash: {error}")]
41 FailedToParseAccountHash {
42 context: &'static str,
44 error: casper_types::addressable_entity::FromStrError,
46 },
47
48 #[error("failed to parse {context} as an addressable entity hash: {error}")]
50 FailedToParseAddressableEntityHash {
51 context: &'static str,
53 error: casper_types::addressable_entity::FromStrError,
55 },
56
57 #[error("failed to parse '{context}' as a uref: {error}")]
59 FailedToParseURef {
60 context: &'static str,
63 error: URefFromStrError,
65 },
66
67 #[error("failed to parse '{context}' as an integer: {error}")]
69 FailedToParseInt {
70 context: &'static str,
73 error: ParseIntError,
75 },
76
77 #[error("failed to parse '{context}' as a bool: {error}")]
79 FailedToParseBool {
80 context: &'static str,
83 error: ParseBoolError,
85 },
86
87 #[error("failed to parse '{context}' as an integer: {error}")]
89 FailedToParseDec {
90 context: &'static str,
93 error: FromDecStrErr,
95 },
96
97 #[error("failed to parse '{context}' as a time diff: {error}")]
99 FailedToParseTimeDiff {
100 context: &'static str,
103 error: DurationError,
105 },
106
107 #[error("failed to parse '{context}' as a timestamp: {error}")]
109 FailedToParseTimestamp {
110 context: &'static str,
113 error: TimestampError,
115 },
116
117 #[error("failed to parse '{context}' as u128, u256, or u512: {error:?}")]
119 FailedToParseUint {
120 context: &'static str,
123 error: UIntParseError,
125 },
126
127 #[error("failed to parse '{context}' as a hash digest: {error:?}")]
129 FailedToParseDigest {
130 context: &'static str,
133 error: casper_types::DigestError,
135 },
136
137 #[error("failed to parse state identifier")]
139 FailedToParseStateIdentifier,
140
141 #[error("conflicting arguments passed '{context}' {args:?}")]
143 ConflictingArguments {
144 context: String,
147 args: Vec<String>,
149 },
150
151 #[error("invalid CLValue error: {0}")]
153 InvalidCLValue(String),
154
155 #[error("invalid argument '{context}': {error}")]
157 InvalidArgument {
158 context: &'static str,
161 error: String,
163 },
164
165 #[error(
167 "failed to parse json-args to JSON: {0}. They should be a JSON Array of Objects, each of \
168 the form {{\"name\":<String>,\"type\":<VALUE>,\"value\":<VALUE>}}"
169 )]
170 FailedToParseJsonArgs(#[from] serde_json::Error),
171
172 #[error(transparent)]
174 JsonArgs(#[from] JsonArgsError),
175
176 #[error(transparent)]
178 Core(#[from] crate::Error),
179
180 #[error("Failed to parse a package address")]
182 FailedToParsePackageAddr,
183
184 #[error("Failed to parse a transfer target")]
186 FailedToParseTransferTarget,
187
188 #[error("Failed to parse a validator public key")]
190 FailedToParseValidatorPublicKey,
191
192 #[error("Failed to parse base16 bytes: {0}")]
194 FailedToParseBase16(#[from] DecodeError),
195
196 #[error("Unexpected transaction args variant")]
198 UnexpectedTransactionArgsVariant,
199
200 #[error("Failed to get auction state")]
202 FailedToGetAuctionState,
203
204 #[error("Attempting to withdraw bid will reduce stake below the minimum amount.")]
206 ReducedStakeBelowMinAmount,
207
208 #[error("Failed to parse the chainspec as raw bytes")]
210 FailedToParseChainspecBytes,
211
212 #[error("Major version is missing when specifying entity version")]
214 MissingMajorVersion,
215}
216
217impl From<CLValueError> for CliError {
218 fn from(error: CLValueError) -> Self {
219 match error {
220 CLValueError::Serialization(bytesrepr_error) => CliError::Core(bytesrepr_error.into()),
221 CLValueError::Type(type_mismatch) => {
222 CliError::InvalidCLValue(type_mismatch.to_string())
223 }
224 }
225 }
226}