casper_client/cli/
error.rs1use std::num::ParseIntError;
2
3use humantime::{DurationError, TimestampError};
4use thiserror::Error;
5
6#[cfg(doc)]
7use casper_types::{account::AccountHash, Key, NamedArg, PublicKey, RuntimeArgs, URef};
8use casper_types::{CLValueError, KeyFromStrError, UIntParseError, URefFromStrError};
9
10use crate::cli::JsonArgsError;
11#[cfg(doc)]
12use crate::{
13 rpcs::{DictionaryItemIdentifier, GlobalStateIdentifier},
14 types::{TimeDiff, Timestamp},
15};
16
17#[derive(Error, Debug)]
19pub enum CliError {
20 #[error("failed to parse {context} as a key: {error}")]
22 FailedToParseKey {
23 context: &'static str,
25 error: KeyFromStrError,
27 },
28
29 #[error("failed to parse {context} as a public key: {error}")]
31 FailedToParsePublicKey {
32 context: String,
34 error: casper_types::crypto::Error,
36 },
37
38 #[error("failed to parse {context} as an account hash: {error}")]
40 FailedToParseAccountHash {
41 context: &'static str,
43 error: casper_types::account::FromStrError,
45 },
46
47 #[error("failed to parse '{context}' as a uref: {error}")]
49 FailedToParseURef {
50 context: &'static str,
53 error: URefFromStrError,
55 },
56
57 #[error("failed to parse '{context}' as an integer: {error}")]
59 FailedToParseInt {
60 context: &'static str,
63 error: ParseIntError,
65 },
66
67 #[error("failed to parse '{context}' as a time diff: {error}")]
69 FailedToParseTimeDiff {
70 context: &'static str,
73 error: DurationError,
75 },
76
77 #[error("failed to parse '{context}' as a timestamp: {error}")]
79 FailedToParseTimestamp {
80 context: &'static str,
83 error: TimestampError,
85 },
86
87 #[error("failed to parse '{context}' as u128, u256, or u512: {error:?}")]
89 FailedToParseUint {
90 context: &'static str,
93 error: UIntParseError,
95 },
96
97 #[error("failed to parse '{context}' as a hash digest: {error:?}")]
99 FailedToParseDigest {
100 context: &'static str,
103 error: casper_hashing::Error,
105 },
106
107 #[error("failed to parse state identifier")]
109 FailedToParseStateIdentifier,
110
111 #[error("conflicting arguments passed '{context}' {args:?}")]
113 ConflictingArguments {
114 context: &'static str,
117 args: Vec<String>,
119 },
120
121 #[error("invalid CLValue error: {0}")]
123 InvalidCLValue(String),
124
125 #[error("invalid argument '{context}': {error}")]
127 InvalidArgument {
128 context: &'static str,
131 error: String,
133 },
134
135 #[error(
137 "failed to parse json-args to JSON: {0}. They should be a JSON Array of Objects, each of \
138 the form {{\"name\":<String>,\"type\":<VALUE>,\"value\":<VALUE>}}"
139 )]
140 FailedToParseJsonArgs(#[from] serde_json::Error),
141
142 #[error(transparent)]
144 JsonArgs(#[from] JsonArgsError),
145
146 #[error(transparent)]
148 Core(#[from] crate::Error),
149}
150
151impl From<CLValueError> for CliError {
152 fn from(error: CLValueError) -> Self {
153 match error {
154 CLValueError::Serialization(bytesrepr_error) => CliError::Core(bytesrepr_error.into()),
155 CLValueError::Type(type_mismatch) => {
156 CliError::InvalidCLValue(type_mismatch.to_string())
157 }
158 }
159 }
160}