Handle file not found gracefully

If the input file provided on the command line cannot be opened, reprt
an error, rather than unwrapping.
This commit is contained in:
Colin Benner 2018-11-20 06:39:15 +01:00
parent e8dd3a0b9e
commit 5beb4ba987

View file

@ -325,7 +325,13 @@ fn main() {
let stdin_handle = stdin();
main_noninteractive(stdin_handle.lock(), false);
},
_ => main_noninteractive(BufReader::new(File::open(name).unwrap()), false)
_ => {
let file = File::open(&name).unwrap_or_else(|e| {
eprintln!("Could not open input file '{}': {}", name, e);
std::process::exit(1);
});
main_noninteractive(BufReader::new(file), false);
}
};
},
// else call the interactive version