Skip to content

Commit 0bea14d

Browse files
authored
Use slog-error-chain for SetupServiceError (#9375)
1 parent d1fd755 commit 0bea14d

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

sled-agent/src/bootstrap/rack_ops.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use sled_agent_config_reconciler::InternalDisksReceiver;
1313
use sled_agent_types::rack_init::RackInitializeRequestParams;
1414
use sled_agent_types::rack_ops::{RackOperationStatus, RssStep};
1515
use slog::Logger;
16+
use slog_error_chain::InlineErrorChain;
1617
use sprockets_tls::keys::SprocketsConfig;
1718
use std::mem;
1819
use std::net::Ipv6Addr;
@@ -96,7 +97,7 @@ impl RssAccess {
9697
RssStatus::InitializationFailed { id, err } => {
9798
RackOperationStatus::InitializationFailed {
9899
id: *id,
99-
message: format!("{err:#}"),
100+
message: InlineErrorChain::new(err).to_string(),
100101
}
101102
}
102103
RssStatus::InitializationPanicked { id } => {
@@ -132,7 +133,7 @@ impl RssAccess {
132133
RssStatus::ResetFailed { id, err } => {
133134
RackOperationStatus::ResetFailed {
134135
id: *id,
135-
message: format!("{err:#}"),
136+
message: InlineErrorChain::new(err).to_string(),
136137
}
137138
}
138139
RssStatus::ResetPanicked { id } => {
@@ -161,7 +162,7 @@ impl RssAccess {
161162
}
162163
RssStatus::InitializationFailed { err, .. } => {
163164
Err(RssAccessError::InitializationFailed {
164-
message: err.to_string(),
165+
message: InlineErrorChain::new(err).to_string(),
165166
})
166167
}
167168
RssStatus::InitializationPanicked { .. } => {
@@ -170,7 +171,9 @@ impl RssAccess {
170171

171172
RssStatus::Resetting { .. } => Err(RssAccessError::StillResetting),
172173
RssStatus::ResetFailed { err, .. } => {
173-
Err(RssAccessError::ResetFailed { message: err.to_string() })
174+
Err(RssAccessError::ResetFailed {
175+
message: InlineErrorChain::new(err).to_string(),
176+
})
174177
}
175178
RssStatus::ResetPanicked { .. } => {
176179
Err(RssAccessError::ResetPanicked)
@@ -227,15 +230,17 @@ impl RssAccess {
227230
}
228231
RssStatus::InitializationFailed { err, .. } => {
229232
Err(RssAccessError::InitializationFailed {
230-
message: err.to_string(),
233+
message: InlineErrorChain::new(err).to_string(),
231234
})
232235
}
233236
RssStatus::InitializationPanicked { .. } => {
234237
Err(RssAccessError::InitializationPanicked)
235238
}
236239
RssStatus::Resetting { .. } => Err(RssAccessError::StillResetting),
237240
RssStatus::ResetFailed { err, .. } => {
238-
Err(RssAccessError::ResetFailed { message: err.to_string() })
241+
Err(RssAccessError::ResetFailed {
242+
message: InlineErrorChain::new(err).to_string(),
243+
})
239244
}
240245
RssStatus::ResetPanicked { .. } => {
241246
Err(RssAccessError::ResetPanicked)

sled-agent/src/rack_setup/service.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ use sled_agent_types::rack_ops::RssStep;
135135
use sled_agent_types::sled::StartSledAgentRequest;
136136
use sled_hardware_types::underlay::BootstrapInterface;
137137
use slog::Logger;
138-
use slog_error_chain::InlineErrorChain;
138+
use slog_error_chain::{InlineErrorChain, SlogInlineError};
139139
use std::collections::{BTreeMap, BTreeSet, btree_map};
140140
use std::collections::{HashMap, HashSet};
141141
use std::iter;
@@ -161,19 +161,19 @@ impl RssProgress {
161161
}
162162

163163
/// Describes errors which may occur while operating the setup service.
164-
#[derive(Error, Debug)]
164+
#[derive(Error, Debug, SlogInlineError)]
165165
pub enum SetupServiceError {
166-
#[error("I/O error while {message}: {err}")]
166+
#[error("I/O error while {message}")]
167167
Io {
168168
message: String,
169169
#[source]
170170
err: std::io::Error,
171171
},
172172

173-
#[error("Failed to access ledger: {0}")]
173+
#[error("Failed to access ledger")]
174174
Ledger(#[from] ledger::Error),
175175

176-
#[error("Cannot create plan for sled services: {0}")]
176+
#[error("Cannot create plan for sled services")]
177177
ServicePlan(#[from] ServicePlanError),
178178

179179
#[error("Bad configuration for setting up rack: {0}")]
@@ -203,37 +203,37 @@ pub enum SetupServiceError {
203203
#[error("Error resetting sled: {0}")]
204204
SledReset(String),
205205

206-
#[error("Error making HTTP request to Sled Agent: {0}")]
206+
#[error("Error making HTTP request to Sled Agent")]
207207
SledApi(#[from] SledAgentError<SledAgentTypes::Error>),
208208

209209
#[error("Sled config not yet reconciled: {0}")]
210210
ConfigNotYetReconciled(String),
211211

212-
#[error("Error making HTTP request to Nexus: {0}")]
212+
#[error("Error making HTTP request to Nexus")]
213213
NexusApi(#[from] NexusError<NexusTypes::Error>),
214214

215215
#[error("Error making HTTP request to NTP Admin Server")]
216216
NtpAdminApi(#[from] NtpAdminError<ntp_admin_client::types::Error>),
217217

218-
#[error("Error contacting ddmd: {0}")]
218+
#[error("Error contacting ddmd")]
219219
DdmError(#[from] DdmError),
220220

221-
#[error("Failed to monitor for peers: {0}")]
221+
#[error("Failed to monitor for peers")]
222222
PeerMonitor(#[from] tokio::sync::broadcast::error::RecvError),
223223

224-
#[error("Failed to construct an HTTP client: {0}")]
225-
HttpClient(reqwest::Error),
224+
#[error("Failed to construct an HTTP client")]
225+
HttpClient(#[from] reqwest::Error),
226226

227-
#[error("Failed to access DNS servers: {0}")]
227+
#[error("Failed to access DNS servers")]
228228
Dns(#[from] DnsError),
229229

230230
#[error("Error during request to Dendrite: {0}")]
231231
Dendrite(String),
232232

233-
#[error("Error during DNS lookup: {0}")]
233+
#[error("Error during DNS lookup")]
234234
DnsResolver(#[from] internal_dns_resolver::ResolveError),
235235

236-
#[error("Bootstore error: {0}")]
236+
#[error("Bootstore error")]
237237
Bootstore(#[from] bootstore::NodeRequestError),
238238

239239
#[error("Failed to convert setup plan to blueprint: {0:#}")]
@@ -417,11 +417,11 @@ impl ServiceInner {
417417
error,
418418
)));
419419
};
420-
let log_failure = |error, delay| {
420+
let log_failure = |error: SetupServiceError, delay| {
421421
warn!(
422422
log,
423423
"failed to set sled Omicron config";
424-
"error" => #%error,
424+
&error,
425425
"retry_after" => ?delay,
426426
);
427427
};
@@ -541,11 +541,11 @@ impl ServiceInner {
541541
))
542542
}
543543
};
544-
let log_failure = |error, delay| {
544+
let log_failure = |error: SetupServiceError, delay| {
545545
warn!(
546546
log,
547547
"sled config not yet reconciled";
548-
"error" => #%error,
548+
&error,
549549
"retry_after" => ?delay,
550550
);
551551
};

0 commit comments

Comments
 (0)