Skip to content

Commit

Permalink
Simplify error mapping using a map_err
Browse files Browse the repository at this point in the history
  • Loading branch information
sfauvel committed Feb 21, 2024
1 parent ae747bd commit 92fa5a3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
7 changes: 2 additions & 5 deletions mithril-aggregator/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ impl MainCommand {
Self::Tools(cmd) => cmd.execute(config_builder).await,
Self::GenerateDoc(cmd) => {
let config_infos = vec![Configuration::extract(), DefaultConfiguration::extract()];
match cmd.execute_with_configurations(&mut MainOpts::command(), &config_infos) {
Ok(()) => StdResult::Ok(()),
Err(message) => StdResult::Err(anyhow!(message)),
}
// Ok(cmd.execute_with_configurations(&mut MainOpts::command(), &config_infos)?)
cmd.execute_with_configurations(&mut MainOpts::command(), &config_infos)
.map_err(|message| anyhow!(message))
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions mithril-client-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ impl ArtifactCommands {
ctx.execute(config_builder).await
}
}
Self::GenerateDoc(cmd) => match cmd.execute(&mut Args::command()) {
Ok(()) => MithrilResult::Ok(()),
Err(message) => MithrilResult::Err(anyhow!(message)),
},
Self::GenerateDoc(cmd) => cmd
.execute(&mut Args::command())
.map_err(|message| anyhow!(message)),
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions mithril-relay/src/commands/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ impl RelayCommands {
Self::Aggregator(cmd) => cmd.execute(config_builder).await,
Self::Signer(cmd) => cmd.execute(config_builder).await,
Self::Passive(cmd) => cmd.execute(config_builder).await,
Self::GenerateDoc(cmd) => match cmd.execute(&mut Args::command()) {
Ok(()) => StdResult::Ok(()),
Err(message) => StdResult::Err(anyhow!(message)),
},
Self::GenerateDoc(cmd) => cmd
.execute(&mut Args::command())
.map_err(|message| anyhow!(message)),
}
}
}
7 changes: 3 additions & 4 deletions mithril-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ async fn main() -> StdResult<()> {
Configuration::extract(),
DefaultConfiguration::extract(),
];
return match cmd.execute_with_configurations(&mut Args::command(), &config_infos) {
Ok(()) => StdResult::Ok(()),
Err(message) => StdResult::Err(anyhow!(message)),
};
return cmd
.execute_with_configurations(&mut Args::command(), &config_infos)
.map_err(|message| anyhow!(message));
}

#[cfg(feature = "bundle_openssl")]
Expand Down
7 changes: 3 additions & 4 deletions mithril-test-lab/mithril-end-to-end/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ async fn main() -> StdResult<()> {
let _guard = slog_scope::set_global_logger(build_logger(&args));

if let Some(EndToEndCommands::GenerateDoc(cmd)) = &args.command {
return match cmd.execute(&mut Args::command()) {
Ok(()) => StdResult::Ok(()),
Err(message) => StdResult::Err(anyhow!(message)),
};
return cmd
.execute(&mut Args::command())
.map_err(|message| anyhow!(message));
}

let server_port = 8080;
Expand Down

0 comments on commit 92fa5a3

Please sign in to comment.