Skip to content

Commit d448daa

Browse files
committed
Refactor error handling in main.rs
1 parent b56d2b5 commit d448daa

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/main.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,27 @@ fn main() -> ExitCode {
4747
fn start_monitoring(params: AuthMonitorParams) -> ExitCode {
4848
let mut auth_monitor = match AuthMonitor::new(params) {
4949
Ok(auth_monitor) => auth_monitor,
50-
Err(e) => {
51-
eprintln!("Error creating AuthMonitor: {}", e);
50+
Err(error) => {
51+
eprintln!("Error creating AuthMonitor: {}", error);
52+
return ExitCode::FAILURE;
53+
}
54+
};
55+
let mut signals = match Signals::new([SIGABRT, SIGINT]) {
56+
Ok(signals) => signals,
57+
Err(error) => {
58+
eprintln!("Error creating signals {}", error);
5259
return ExitCode::FAILURE;
5360
}
5461
};
55-
let mut signals = Signals::new([SIGABRT, SIGINT]).unwrap();
5662
loop {
5763
auth_monitor.update(shutdown);
58-
let signal = signals.pending().next();
59-
if signal.is_some() {
60-
println!("Received signal {}, stopping...", signal.unwrap());
61-
return ExitCode::SUCCESS;
64+
match signals.pending().next() {
65+
Some(signal) => {
66+
println!("Received signal {}, stopping...", signal);
67+
return ExitCode::SUCCESS;
68+
}
69+
None => thread::sleep(SLEEP_DURATION),
6270
}
63-
thread::sleep(SLEEP_DURATION);
6471
}
6572
}
6673

0 commit comments

Comments
 (0)