Skip to content

Commit

Permalink
refactor: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wfxr committed Nov 11, 2020
1 parent 7099262 commit afd5de2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/bin/code-minimap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ mod util;
use cli::{CompletionOpt, Opt, StructOpt, Subcommand};
use std::fs::File;
use std::io::{self, BufRead, BufReader};
use std::process;

fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() {
if let Err(e) = run() {
eprintln!("{}: {}", env!("CARGO_PKG_NAME"), e);
process::exit(1)
}
}

fn run() -> Result<(), Box<dyn std::error::Error>> {
util::reset_signal_pipe_handler();
let opt: Opt = Opt::from_args();
match &opt.subcommand {
Expand All @@ -16,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(path) => Box::new(BufReader::new(File::open(path)?)),
None => Box::new(BufReader::new(io::stdin())),
};
code_minimap::print(reader, opt.hscale, opt.vscale, opt.padding).unwrap();
code_minimap::print(reader, opt.hscale, opt.vscale, opt.padding)?;
}
}
Ok(())
Expand Down

0 comments on commit afd5de2

Please sign in to comment.