-
Notifications
You must be signed in to change notification settings - Fork 298
/
error.rs
174 lines (149 loc) · 6.68 KB
/
error.rs
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
use ic_http_utils::file_downloader::FileDownloadError;
use ic_image_upgrader::error::UpgradeError;
use ic_types::replica_version::ReplicaVersionParseError;
use ic_types::{registry::RegistryClientError, NodeId, RegistryVersion, ReplicaVersion, SubnetId};
use std::error::Error;
use std::fmt;
use std::io;
use std::path::{Path, PathBuf};
pub type OrchestratorResult<T> = Result<T, OrchestratorError>;
/// Enumerates the possible errors that Orchestrator may encounter
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum OrchestratorError {
/// The given node is not assigned to any Subnet
NodeUnassignedError(NodeId, RegistryVersion),
/// The given subnet ID does not map to a `SubnetRecord` at the given
/// version
SubnetMissingError(SubnetId, RegistryVersion),
/// The given node id does not map to an `ApiBoundaryNodeRecord` at the
/// given version
ApiBoundaryNodeMissingError(NodeId, RegistryVersion),
/// An error occurred when querying the Registry that prevents Orchestrator
/// from making progress
RegistryClientError(RegistryClientError),
/// The genesis or recovery CUP failed to be constructed
MakeRegistryCupError(SubnetId, RegistryVersion),
/// The given replica version does not have an entry in the Registry
ReplicaVersionMissingError(ReplicaVersion, RegistryVersion),
/// A replica version (of a subnet record) could not be parsed
ReplicaVersionParseError(ReplicaVersionParseError),
/// An IO error occurred
IoError(String, io::Error),
/// An error occurred when downloading, extracting or checking the hash of a
/// downloaded file
FileDownloadError(FileDownloadError),
/// Failed to exec a new Orchestrator binary
ExecError(PathBuf, exec::Error),
/// The provided configuration file (`ic.json5`) has invalid content.
InvalidConfigurationError(String),
/// Generic upgrade error
UpgradeError(String),
/// Generic error while handling reboot time
RebootTimeError(String),
/// Generic error while monitoring key changes
ThresholdKeyMonitoringError(String),
/// SNP error while registering a SEV-SNP node
SnpError(String),
}
impl OrchestratorError {
pub(crate) fn file_write_error(file_path: &Path, e: io::Error) -> Self {
OrchestratorError::IoError(format!("Failed to write to file: {:?}", file_path), e)
}
pub(crate) fn invalid_configuration_error(msg: impl ToString) -> Self {
OrchestratorError::InvalidConfigurationError(msg.to_string())
}
pub(crate) fn key_monitoring_error(msg: impl ToString) -> Self {
OrchestratorError::ThresholdKeyMonitoringError(msg.to_string())
}
pub(crate) fn snp_error(msg: impl ToString) -> Self {
OrchestratorError::SnpError(msg.to_string())
}
}
impl fmt::Display for OrchestratorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OrchestratorError::NodeUnassignedError(node_id, registry_version) => write!(
f,
"Node {:?} is not found in any subnet at registry version {:?}",
node_id, registry_version
),
OrchestratorError::RegistryClientError(e) => write!(f, "{:?}", e),
OrchestratorError::ReplicaVersionMissingError(replica_version, registry_version) => {
write!(
f,
"Replica version {} was not found in the Registry at registry version {:?}",
replica_version, registry_version
)
}
OrchestratorError::IoError(msg, e) => {
write!(f, "IO error, message: {:?}, error: {:?}", msg, e)
}
OrchestratorError::FileDownloadError(e) => write!(f, "File download error: {:?}", e),
OrchestratorError::ExecError(path, e) => write!(
f,
"Failed to exec new Orchestrator process: {:?}, error: {:?}",
path, e
),
OrchestratorError::InvalidConfigurationError(msg) => {
write!(f, "Invalid configuration: {}", msg)
}
OrchestratorError::RebootTimeError(msg) => {
write!(f, "Failed to read or write reboot time: {}", msg)
}
OrchestratorError::ThresholdKeyMonitoringError(msg) => {
write!(
f,
"Failed to read or write threshold key changed metric: {}",
msg
)
}
OrchestratorError::SubnetMissingError(subnet_id, registry_version) => write!(
f,
"Subnet ID {:?} does not exist in the Registry at registry version {:?}",
subnet_id, registry_version
),
OrchestratorError::ApiBoundaryNodeMissingError(node_id, registry_version) => write!(
f,
"Api Boundary Node ID {:?} does not exist in the Registry at registry version {:?}",
node_id, registry_version
),
OrchestratorError::ReplicaVersionParseError(e) => {
write!(f, "Failed to parse replica version: {}", e)
}
OrchestratorError::MakeRegistryCupError(subnet_id, registry_version) => write!(
f,
"Failed to construct the genesis/recovery CUP, subnet_id: {}, registry_version: {}",
subnet_id, registry_version,
),
OrchestratorError::UpgradeError(msg) => write!(f, "Failed to upgrade: {}", msg),
OrchestratorError::SnpError(msg) => write!(f, "SEV-SNP Error: {}", msg),
}
}
}
impl From<FileDownloadError> for OrchestratorError {
fn from(e: FileDownloadError) -> Self {
OrchestratorError::FileDownloadError(e)
}
}
impl From<UpgradeError> for OrchestratorError {
fn from(e: UpgradeError) -> Self {
match e {
UpgradeError::IoError(s, err) => OrchestratorError::IoError(s, err),
UpgradeError::FileDownloadError(e) => OrchestratorError::FileDownloadError(e),
UpgradeError::GenericError(s) => OrchestratorError::UpgradeError(s),
UpgradeError::RebootTimeError(s) => OrchestratorError::RebootTimeError(s),
}
}
}
impl From<OrchestratorError> for UpgradeError {
fn from(e: OrchestratorError) -> UpgradeError {
match e {
OrchestratorError::IoError(s, err) => UpgradeError::IoError(s, err),
OrchestratorError::FileDownloadError(e) => UpgradeError::FileDownloadError(e),
OrchestratorError::RebootTimeError(s) => UpgradeError::RebootTimeError(s),
err => UpgradeError::GenericError(err.to_string()),
}
}
}
impl Error for OrchestratorError {}