1use std::{io, path::PathBuf};
2
3use thiserror::Error;
4
5use casper_types::{bytesrepr::Error as ToBytesError, crypto, Key};
6#[cfg(doc)]
7use casper_types::{CLValue, Deploy, TimeDiff, Timestamp, URef};
8
9use crate::{
10 cli::{DeployBuilderError, TransactionV1BuilderError},
11 validation::ValidateResponseError,
12 JsonRpcId,
13};
14
15#[derive(Error, Debug)]
17pub enum Error {
18 #[error(transparent)]
20 DeploySize(#[from] casper_types::DeployExcessiveSizeError),
21
22 #[error(transparent)]
24 DeployBuild(#[from] DeployBuilderError),
25
26 #[error(transparent)]
28 TransactionBuild(#[from] TransactionV1BuilderError),
29 #[error("expected {} but got {}", .expected_variant, .actual)]
31 InvalidKeyVariant {
32 expected_variant: String,
34 actual: Key,
36 },
37
38 #[error("failed to get response for rpc-id {rpc_id} {rpc_method}: {error}")]
40 FailedToGetResponse {
41 rpc_id: JsonRpcId,
43 rpc_method: &'static str,
45 error: reqwest::Error,
47 },
48
49 #[error("response for rpc-id {rpc_id} {rpc_method} is http error: {error}")]
51 ResponseIsHttpError {
52 rpc_id: JsonRpcId,
54 rpc_method: &'static str,
56 error: reqwest::Error,
58 },
59
60 #[error("failed to parse response for rpc-id {rpc_id} {rpc_method}: {error}")]
62 FailedToParseResponse {
63 rpc_id: JsonRpcId,
65 rpc_method: &'static str,
67 error: reqwest::Error,
69 },
70
71 #[error("response for rpc-id {rpc_id} {rpc_method} is json-rpc error: {error}")]
73 ResponseIsRpcError {
74 rpc_id: JsonRpcId,
76 rpc_method: &'static str,
78 error: jsonrpc_lite::Error,
80 },
81
82 #[error(
84 "response {response_kind} for rpc-id {rpc_id} {rpc_method} is not valid because {source:?}: {response}"
85 )]
86 InvalidRpcResponse {
87 rpc_id: JsonRpcId,
89 rpc_method: &'static str,
91 response_kind: &'static str,
93 response: serde_json::Value,
95 source: Option<serde_json::Error>,
97 },
98
99 #[error("failed to encode to json: {context}: {error}")]
101 FailedToEncodeToJson {
102 context: &'static str,
104 error: serde_json::Error,
106 },
107
108 #[error("failed to decode from json: {context}: {error}")]
110 FailedToDecodeFromJson {
111 context: &'static str,
113 error: serde_json::Error,
115 },
116
117 #[error("file at {} already exists", .0.display())]
119 FileAlreadyExists(PathBuf),
120
121 #[error("empty path provided as output dir for keygen")]
123 EmptyKeygenPath,
124
125 #[error("unsupported keygen algorithm: {0}")]
127 UnsupportedAlgorithm(String),
128
129 #[error("input/output error: {context}: {error}")]
131 IoError {
132 context: String,
135 error: io::Error,
137 },
138
139 #[error("serialization error: {0}")]
141 ToBytesError(ToBytesError),
142
143 #[error("cryptographic error: {context}: {error}")]
145 CryptoError {
146 context: &'static str,
149 error: crypto::ErrorExt,
151 },
152
153 #[error("invalid response: {0}")]
155 ResponseFailedValidation(#[from] ValidateResponseError),
156
157 #[error("invalid UTF-8 string: {context}: {error}")]
159 Utf8Error {
160 context: &'static str,
162 error: std::str::Utf8Error,
164 },
165
166 #[error("contract verification failed")]
168 ContractVerificationFailed,
169
170 #[error("failed to construct HTTP client")]
172 FailedToConstructHttpClient,
173
174 #[error("failed to parse node address as valid URL")]
176 FailedToParseNodeAddress,
177}
178
179impl From<ToBytesError> for Error {
180 fn from(error: ToBytesError) -> Self {
181 Error::ToBytesError(error)
182 }
183}