Skip to content

Commit

Permalink
Prefer anyhow!(err) over err.into()
Browse files Browse the repository at this point in the history
  • Loading branch information
papertigers committed Nov 6, 2023
1 parent f2a4fe5 commit ad8e5d6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gateway/src/bin/mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn do_run() -> Result<(), CmdError> {
#[cfg(target_os = "illumos")]
fn read_smf_config() -> Result<ConfigProperties, CmdError> {
fn scf_to_cmd_err(err: illumos_utils::scf::ScfError) -> CmdError {
CmdError::Failure(err.into())
CmdError::Failure(anyhow!(err))
}

use illumos_utils::scf::ScfHandle;
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/bin/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn do_run() -> Result<(), CmdError> {
let args = Args::parse();

let config = Config::from_file(args.config_file_path)
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;

if args.openapi {
run_openapi_external().map_err(|err| CmdError::Failure(anyhow!(err)))
Expand Down
12 changes: 6 additions & 6 deletions sled-agent/src/bin/sled-agent-sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// TODO see the TODO for nexus.

use anyhow::Context;
use anyhow::{anyhow, Context};
use camino::Utf8PathBuf;
use clap::Parser;
use dropshot::ConfigDropshot;
Expand Down Expand Up @@ -95,8 +95,8 @@ async fn main() {
async fn do_run() -> Result<(), CmdError> {
let args = Args::parse();

let tmp =
camino_tempfile::tempdir().map_err(|e| CmdError::Failure(e.into()))?;
let tmp = camino_tempfile::tempdir()
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
let config = Config {
id: args.uuid,
sim_mode: args.sim_mode,
Expand Down Expand Up @@ -125,10 +125,10 @@ async fn do_run() -> Result<(), CmdError> {
(Some(cert_path), Some(key_path)) => {
let cert_bytes = std::fs::read_to_string(&cert_path)
.with_context(|| format!("read {:?}", &cert_path))
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
let key_bytes = std::fs::read_to_string(&key_path)
.with_context(|| format!("read {:?}", &key_path))
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
Some(NexusTypes::Certificate { cert: cert_bytes, key: key_bytes })
}
_ => {
Expand All @@ -147,5 +147,5 @@ async fn do_run() -> Result<(), CmdError> {

run_standalone_server(&config, &rss_args)
.await
.map_err(|e| CmdError::Failure(e.into()))
.map_err(|e| CmdError::Failure(anyhow!(e)))
}
8 changes: 4 additions & 4 deletions sled-agent/src/bin/sled-agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn do_run() -> Result<(), CmdError> {
},
Args::Run { config_path } => {
let config = SledConfig::from_file(&config_path)
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;

// - Sled agent starts with the normal config file - typically
// called "config.toml".
Expand All @@ -82,15 +82,15 @@ async fn do_run() -> Result<(), CmdError> {
let rss_config = if rss_config_path.exists() {
Some(
RssConfig::from_file(rss_config_path)
.map_err(|e| CmdError::Failure(e.into()))?,
.map_err(|e| CmdError::Failure(anyhow!(e)))?,
)
} else {
None
};

let server = bootstrap_server::Server::start(config)
.await
.map_err(|err| CmdError::Failure(err.into()))?;
.map_err(|err| CmdError::Failure(anyhow!(err)))?;

// If requested, automatically supply the RSS configuration.
//
Expand All @@ -102,7 +102,7 @@ async fn do_run() -> Result<(), CmdError> {
// abandon the server.
Ok(_) | Err(RssAccessError::AlreadyInitialized) => {}
Err(e) => {
return Err(CmdError::Failure(e.into()));
return Err(CmdError::Failure(anyhow!(e)));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions sp-sim/src/bin/sp-sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use anyhow::Result;
use anyhow::{anyhow, Result};
use clap::Parser;
use omicron_common::cmd::{fatal, CmdError};
use sp_sim::config::Config;
Expand All @@ -27,14 +27,14 @@ async fn main() {
async fn do_run() -> Result<(), CmdError> {
let args = Args::parse();
let config = Config::from_file(args.config_file_path)
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;

let log =
sp_sim::logger(&config).map_err(|e| CmdError::Failure(e.into()))?;
sp_sim::logger(&config).map_err(|e| CmdError::Failure(anyhow!(e)))?;

let _rack = SimRack::start(&config, &log)
.await
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;

// for now, do nothing except let the spawned tasks run. in the future
// (or when used as a library), the expectation is that a caller can
Expand Down
6 changes: 3 additions & 3 deletions wicketd/src/bin/wicketd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ async fn do_run() -> Result<(), CmdError> {
} => {
let baseboard = if let Some(baseboard_file) = baseboard_file {
let baseboard_file = std::fs::read_to_string(baseboard_file)
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
let baseboard: Baseboard =
serde_json::from_str(&baseboard_file)
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;

// TODO-correctness `Baseboard::unknown()` is slated for removal
// after some refactoring in sled-agent, at which point we'll
Expand All @@ -113,7 +113,7 @@ async fn do_run() -> Result<(), CmdError> {
Some(addr) => Some(Ipv6Subnet::new(addr)),
None if read_smf_config => {
let smf_values = SmfConfigValues::read_current()
.map_err(|e| CmdError::Failure(e.into()))?;
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
smf_values.rack_subnet
}
None => None,
Expand Down

0 comments on commit ad8e5d6

Please sign in to comment.