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
use cubist_proxy::FatalErr;
use reqwest::Url;
use std::{path::PathBuf, process::ExitStatus};
use thiserror::Error;
use url;
#[derive(Debug, Error)]
pub enum Error {
#[error("Could not resolve hostname {0:?}")]
CannotResolveHostname(String),
#[error("Unsupported platform: {name} is not supported on platform {os}-{arch}. It is only supported on {supported}.")]
UnsupportedPlatformError {
name: String,
os: String,
arch: String,
supported: String,
},
#[error("Number of specified binaries ({num_binaries}) and hashes ({num_hashes}) must match")]
MismatchedBinariesAndHashes {
num_binaries: usize,
num_hashes: usize,
},
#[error("No binaries specified for {0}")]
MissingBinaries(String),
#[error(transparent)]
ProviderError(#[from] ProviderError),
#[error(transparent)]
EthersProviderError(#[from] ethers::providers::ProviderError),
#[error(transparent)]
DownloadError(#[from] DownloadError),
#[error("{0}. Path: {1}")]
FsError(&'static str, PathBuf, #[source] std::io::Error),
#[error("{0}. Path: {1:?}")]
JsonError(&'static str, Option<PathBuf>, #[source] serde_json::Error),
#[error("IO error")]
IOError(#[source] std::io::Error),
#[error("Server timeout: {0} failed to start: {1}")]
ServerTimeout(String, String),
#[error("Proxy error")]
ProxyError(#[from] FatalErr),
#[error("Config error")]
ConfigError(#[from] cubist_config::ConfigError),
#[error("{0} process terminated unexpectedly, exit status {1}")]
ProcessTerminated(String, ExitStatus),
}
#[derive(Debug, Error)]
pub enum ProviderError {
#[error("Setting up provider failed: {0}")]
SetupError(String),
#[error("Starting node failed: {0}")]
StartError(String),
#[error("Timeout while connecting to server: {0}")]
ServerTimeout(String),
#[error("Error parsing URL: {0}")]
UrlParseError(#[from] url::ParseError),
}
#[derive(Debug, Error)]
pub enum DownloadError {
#[error("Downloaded file {0} is missing")]
MissingDownloadedFile(PathBuf),
#[error("Hash value for {file} does not match expected value: {expected} != {actual}")]
IncorrectHash {
file: PathBuf,
expected: blake3::Hash,
actual: blake3::Hash,
},
#[error("Malformed download: {0}")]
MalformedDownload(String),
#[error("Request error; url = {0}")]
RequestError(Url, #[source] reqwest::Error),
#[error("Failed to save downloaded file to {0}")]
SaveError(PathBuf, #[source] std::io::Error),
}
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[macro_export]
macro_rules! setup_error {
($msg:literal $(,)?) => {
return $crate::error::ProviderError::SetupError($msg)
};
($fmt:expr, $($arg:tt)*) => {
return $crate::error::ProviderError::SetupError(format!($fmt, $($arg)*))
};
}
#[macro_export]
macro_rules! start_error {
($msg:literal $(,)?) => {
return $crate::error::ProviderError::StartError($msg)
};
($fmt:expr, $($arg:tt)*) => {
return $crate::error::ProviderError::StartError(format!($fmt, $($arg)*))
};
}