Skip to content

Commit afd5de2

Browse files
committed
refactor: improve error handling
1 parent 7099262 commit afd5de2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/bin/code-minimap/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ mod util;
33
use cli::{CompletionOpt, Opt, StructOpt, Subcommand};
44
use std::fs::File;
55
use std::io::{self, BufRead, BufReader};
6+
use std::process;
67

7-
fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
fn main() {
9+
if let Err(e) = run() {
10+
eprintln!("{}: {}", env!("CARGO_PKG_NAME"), e);
11+
process::exit(1)
12+
}
13+
}
14+
15+
fn run() -> Result<(), Box<dyn std::error::Error>> {
816
util::reset_signal_pipe_handler();
917
let opt: Opt = Opt::from_args();
1018
match &opt.subcommand {
@@ -16,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1624
Some(path) => Box::new(BufReader::new(File::open(path)?)),
1725
None => Box::new(BufReader::new(io::stdin())),
1826
};
19-
code_minimap::print(reader, opt.hscale, opt.vscale, opt.padding).unwrap();
27+
code_minimap::print(reader, opt.hscale, opt.vscale, opt.padding)?;
2028
}
2129
}
2230
Ok(())

0 commit comments

Comments
 (0)