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
use std::{io, path::PathBuf};
use thiserror::Error;
use casper_types::{bytesrepr::Error as ToBytesError, crypto, Key};
#[cfg(doc)]
use casper_types::{CLValue, Deploy, TimeDiff, Timestamp, URef};
use crate::{
cli::{DeployBuilderError, TransactionV1BuilderError},
validation::ValidateResponseError,
JsonRpcId,
};
/// Errors that may be returned by `casper_client` functions.
#[derive(Error, Debug)]
pub enum Error {
/// [`Deploy`] size too large.
#[error(transparent)]
DeploySize(#[from] casper_types::DeployExcessiveSizeError),
/// Failed to build [`Deploy`].
#[error(transparent)]
DeployBuild(#[from] DeployBuilderError),
/// Failed to build Transaction
#[error(transparent)]
TransactionBuild(#[from] TransactionV1BuilderError),
/// Invalid [`Key`] variant.
#[error("expected {} but got {}", .expected_variant, .actual)]
InvalidKeyVariant {
/// The expected variant.
expected_variant: String,
/// The actual key provided.
actual: Key,
},
/// Failed to get a response from the node.
#[error("failed to get response for rpc-id {rpc_id} {rpc_method}: {error}")]
FailedToGetResponse {
/// The JSON-RPC ID.
rpc_id: JsonRpcId,
/// The JSON-RPC request method.
rpc_method: &'static str,
/// The reported error.
error: reqwest::Error,
},
/// JSON-RPC error returned from the node.
#[error("response for rpc-id {rpc_id} {rpc_method} is http error: {error}")]
ResponseIsHttpError {
/// The JSON-RPC ID.
rpc_id: JsonRpcId,
/// The JSON-RPC request method.
rpc_method: &'static str,
/// The reported error.
error: reqwest::Error,
},
/// Failed to parse the response.
#[error("failed to parse response for rpc-id {rpc_id} {rpc_method}: {error}")]
FailedToParseResponse {
/// The JSON-RPC ID.
rpc_id: JsonRpcId,
/// The JSON-RPC request method.
rpc_method: &'static str,
/// The reported error.
error: reqwest::Error,
},
/// JSON-RPC error returned from the node.
#[error("response for rpc-id {rpc_id} {rpc_method} is json-rpc error: {error}")]
ResponseIsRpcError {
/// The JSON-RPC ID.
rpc_id: JsonRpcId,
/// The JSON-RPC request method.
rpc_method: &'static str,
/// The reported error.
error: jsonrpc_lite::Error,
},
/// Invalid response returned from the node.
#[error(
"response {response_kind} for rpc-id {rpc_id} {rpc_method} is not valid because {source:?}: {response}"
)]
InvalidRpcResponse {
/// The JSON-RPC ID.
rpc_id: JsonRpcId,
/// The JSON-RPC request method.
rpc_method: &'static str,
/// What kind of Json response was received.
response_kind: &'static str,
/// The JSON response.
response: serde_json::Value,
/// If available, the original error from Serde.
source: Option<serde_json::Error>,
},
/// Failed to encode to JSON.
#[error("failed to encode to json: {context}: {error}")]
FailedToEncodeToJson {
/// Contextual description of where this error occurred.
context: &'static str,
/// Underlying encoding error.
error: serde_json::Error,
},
/// Failed to decode from JSON.
#[error("failed to decode from json: {context}: {error}")]
FailedToDecodeFromJson {
/// Contextual description of where this error occurred.
context: &'static str,
/// Underlying decoding error.
error: serde_json::Error,
},
/// Failed to create new file because it already exists.
#[error("file at {} already exists", .0.display())]
FileAlreadyExists(PathBuf),
/// Empty path provided as output dir for keygen.
#[error("empty path provided as output dir for keygen")]
EmptyKeygenPath,
/// Unsupported keygen algorithm.
#[error("unsupported keygen algorithm: {0}")]
UnsupportedAlgorithm(String),
/// Context-adding wrapper for `std::io::Error`.
#[error("input/output error: {context}: {error}")]
IoError {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: String,
/// std::io::Error raised during the operation in question.
error: io::Error,
},
/// Failed to serialize to bytes.
#[error("serialization error: {0}")]
ToBytesError(ToBytesError),
/// Cryptographic error.
#[error("cryptographic error: {context}: {error}")]
CryptoError {
/// Contextual description of where this error occurred including relevant paths,
/// filenames, etc.
context: &'static str,
/// Underlying crypto error.
error: crypto::ErrorExt,
},
/// Failed to validate response.
#[error("invalid response: {0}")]
ResponseFailedValidation(#[from] ValidateResponseError),
/// An error that occurs when attempting to use a non UTF-8 string for a transaction.
#[error("invalid UTF-8 string: {context}: {error}")]
Utf8Error {
/// Contextual description of where this error occurred.
context: &'static str,
/// Underlying error.
error: std::str::Utf8Error,
},
/// Failed to verify contract.
#[error("contract verification failed")]
ContractVerificationFailed,
/// Failed to construct HTTP client.
#[error("failed to construct HTTP client")]
FailedToConstructHttpClient,
/// Failed to parse provided node address as URL.
#[error("failed to parse node address as valid URL")]
FailedToParseNodeAddress,
}
impl From<ToBytesError> for Error {
fn from(error: ToBytesError) -> Self {
Error::ToBytesError(error)
}
}