Skip to content

Commit 0daf3df

Browse files
committed
Make signer main function return an StdResult
1 parent 975cabd commit 0daf3df

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mithril-signer/src/main.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use anyhow::Context;
12
use clap::Parser;
23
use slog::{o, Drain, Level, Logger};
34
use slog_scope::debug;
45
use std::path::PathBuf;
56
use std::sync::Arc;
67
use std::time::Duration;
78

9+
use mithril_common::StdResult;
810
use mithril_signer::{
911
Configuration, DefaultConfiguration, ProductionServiceBuilder, ServiceBuilder, SignerRunner,
1012
SignerState, StateMachine,
@@ -72,7 +74,7 @@ fn build_logger(min_level: Level) -> Logger {
7274
}
7375

7476
#[tokio::main]
75-
async fn main() -> Result<(), String> {
77+
async fn main() -> StdResult<()> {
7678
// Load args
7779
let args = Args::parse();
7880
let _guard = slog_scope::set_global_logger(build_logger(args.log_level()));
@@ -85,9 +87,9 @@ async fn main() -> Result<(), String> {
8587
// Load config
8688
let config: Configuration = config::Config::builder()
8789
.set_default("disable_digests_cache", args.disable_digests_cache)
88-
.map_err(|e| e.to_string())?
90+
.with_context(|| "configuration error: could not set `disable_digests_cache`")?
8991
.set_default("reset_digests_cache", args.reset_digests_cache)
90-
.map_err(|e| e.to_string())?
92+
.with_context(|| "configuration error: could not set `reset_digests_cache`")?
9193
.add_source(DefaultConfiguration::default())
9294
.add_source(
9395
config::File::with_name(&format!(
@@ -99,19 +101,21 @@ async fn main() -> Result<(), String> {
99101
)
100102
.add_source(config::Environment::default())
101103
.build()
102-
.map_err(|e| format!("configuration build error: {e}"))?
104+
.with_context(|| "configuration build error")?
103105
.try_deserialize()
104-
.map_err(|e| format!("configuration deserialize error: {e}"))?;
106+
.with_context(|| "configuration deserialize error")?;
107+
105108
let services = ProductionServiceBuilder::new(&config)
106109
.build()
107110
.await
108-
.map_err(|e| e.to_string())?;
109-
debug!("Started"; "run_mode" => &args.run_mode, "config" => format!("{config:?}"));
111+
.with_context(|| "services initialization error")?;
110112

113+
debug!("Started"; "run_mode" => &args.run_mode, "config" => format!("{config:?}"));
111114
let mut state_machine = StateMachine::new(
112115
SignerState::Init,
113116
Box::new(SignerRunner::new(config.clone(), services)),
114117
Duration::from_millis(config.run_interval),
115118
);
116-
state_machine.run().await.map_err(|e| e.to_string())
119+
120+
state_machine.run().await.map_err(|e| e.into())
117121
}

0 commit comments

Comments
 (0)