1
+ use anyhow:: Context ;
1
2
use clap:: Parser ;
2
3
use slog:: { o, Drain , Level , Logger } ;
3
4
use slog_scope:: debug;
4
5
use std:: path:: PathBuf ;
5
6
use std:: sync:: Arc ;
6
7
use std:: time:: Duration ;
7
8
9
+ use mithril_common:: StdResult ;
8
10
use mithril_signer:: {
9
11
Configuration , DefaultConfiguration , ProductionServiceBuilder , ServiceBuilder , SignerRunner ,
10
12
SignerState , StateMachine ,
@@ -72,7 +74,7 @@ fn build_logger(min_level: Level) -> Logger {
72
74
}
73
75
74
76
#[ tokio:: main]
75
- async fn main ( ) -> Result < ( ) , String > {
77
+ async fn main ( ) -> StdResult < ( ) > {
76
78
// Load args
77
79
let args = Args :: parse ( ) ;
78
80
let _guard = slog_scope:: set_global_logger ( build_logger ( args. log_level ( ) ) ) ;
@@ -85,9 +87,9 @@ async fn main() -> Result<(), String> {
85
87
// Load config
86
88
let config: Configuration = config:: Config :: builder ( )
87
89
. 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`" ) ?
89
91
. 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`" ) ?
91
93
. add_source ( DefaultConfiguration :: default ( ) )
92
94
. add_source (
93
95
config:: File :: with_name ( & format ! (
@@ -99,19 +101,21 @@ async fn main() -> Result<(), String> {
99
101
)
100
102
. add_source ( config:: Environment :: default ( ) )
101
103
. build ( )
102
- . map_err ( |e| format ! ( "configuration build error: {e}" ) ) ?
104
+ . with_context ( || "configuration build error" ) ?
103
105
. try_deserialize ( )
104
- . map_err ( |e| format ! ( "configuration deserialize error: {e}" ) ) ?;
106
+ . with_context ( || "configuration deserialize error" ) ?;
107
+
105
108
let services = ProductionServiceBuilder :: new ( & config)
106
109
. build ( )
107
110
. 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" ) ?;
110
112
113
+ debug ! ( "Started" ; "run_mode" => & args. run_mode, "config" => format!( "{config:?}" ) ) ;
111
114
let mut state_machine = StateMachine :: new (
112
115
SignerState :: Init ,
113
116
Box :: new ( SignerRunner :: new ( config. clone ( ) , services) ) ,
114
117
Duration :: from_millis ( config. run_interval ) ,
115
118
) ;
116
- state_machine. run ( ) . await . map_err ( |e| e. to_string ( ) )
119
+
120
+ state_machine. run ( ) . await . map_err ( |e| e. into ( ) )
117
121
}
0 commit comments