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, URef};
8
9#[cfg(doc)]
10use crate::types::{Deploy, DeployBuilder, TimeDiff, Timestamp};
11use crate::{validation::ValidateResponseError, JsonRpcId};
12
13#[derive(Error, Debug)]
15pub enum Error {
16 #[error("deploy size of {actual_deploy_size} bytes exceeds limit of {max_deploy_size}")]
18 DeploySizeTooLarge {
19 max_deploy_size: u32,
21 actual_deploy_size: usize,
23 },
24
25 #[error("deploy requires payment code - use `with_payment` or `with_standard_payment`")]
30 DeployMissingPaymentCode,
31
32 #[error("expected {} but got {}", .expected_variant, .actual)]
34 InvalidKeyVariant {
35 expected_variant: String,
37 actual: Key,
39 },
40
41 #[error("failed to get response for rpc-id {rpc_id} {rpc_method}: {error}")]
43 FailedToGetResponse {
44 rpc_id: JsonRpcId,
46 rpc_method: &'static str,
48 error: reqwest::Error,
50 },
51
52 #[error("response for rpc-id {rpc_id} {rpc_method} is http error: {error}")]
54 ResponseIsHttpError {
55 rpc_id: JsonRpcId,
57 rpc_method: &'static str,
59 error: reqwest::Error,
61 },
62
63 #[error("failed to parse response for rpc-id {rpc_id} {rpc_method}: {error}")]
65 FailedToParseResponse {
66 rpc_id: JsonRpcId,
68 rpc_method: &'static str,
70 error: reqwest::Error,
72 },
73
74 #[error("response for rpc-id {rpc_id} {rpc_method} is json-rpc error: {error}")]
76 ResponseIsRpcError {
77 rpc_id: JsonRpcId,
79 rpc_method: &'static str,
81 error: jsonrpc_lite::Error,
83 },
84
85 #[error(
87 "response {response_kind} for rpc-id {rpc_id} {rpc_method} is not valid because {source:?}: {response}"
88 )]
89 InvalidRpcResponse {
90 rpc_id: JsonRpcId,
92 rpc_method: &'static str,
94 response_kind: &'static str,
96 response: serde_json::Value,
98 source: Option<serde_json::Error>,
100 },
101
102 #[error("failed to encode to json: {context}: {error}")]
104 FailedToEncodeToJson {
105 context: &'static str,
107 error: serde_json::Error,
109 },
110
111 #[error("failed to decode from json: {context}: {error}")]
113 FailedToDecodeFromJson {
114 context: &'static str,
116 error: serde_json::Error,
118 },
119
120 #[error("file at {} already exists", .0.display())]
122 FileAlreadyExists(PathBuf),
123
124 #[error("empty path provided as output dir for keygen")]
126 EmptyKeygenPath,
127
128 #[error("unsupported keygen algorithm: {0}")]
130 UnsupportedAlgorithm(String),
131
132 #[error("input/output error: {context}: {error}")]
134 IoError {
135 context: String,
138 error: io::Error,
140 },
141
142 #[error("serialization error: {0}")]
144 ToBytesError(ToBytesError),
145
146 #[error("cryptographic error: {context}: {error}")]
148 CryptoError {
149 context: &'static str,
152 error: crypto::ErrorExt,
154 },
155
156 #[error("invalid response: {0}")]
158 ResponseFailedValidation(#[from] ValidateResponseError),
159}
160
161impl From<ToBytesError> for Error {
162 fn from(error: ToBytesError) -> Self {
163 Error::ToBytesError(error)
164 }
165}