Skip to content

Commit

Permalink
Improvement: Better OS error display
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Nov 1, 2024
1 parent e821b28 commit 3e1cfb0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Of note:
- The changelog 2015.5.2 has been rewritten from each commit content.
- This file may be amended entirely in the future to adhere to the [GNU Changelog style](https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs)

## Unversioned
### Changed
- Small fix to OS error outputs.

## [2018.6.3]
### Changed
- Replaced [Clap](https://github.com/clap-rs/clap) with [Argh](https://github.com/google/argh) for CLI input parsing, binaries are now 300k lighter.
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ fn main() {
let input: String = match fetch_input(args.input) {
Ok(input_data) => input_data,
Err(error) => {
eprintln!("advent-rs: {}", error);
let error_str = error.to_string();
eprintln!(
"advent-rs: {}",
error_str.split(" (os error").next().unwrap()
);
std::process::exit(1);
}
};
Expand Down
13 changes: 13 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ fn invalid_year_past() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[test]
fn non_existing_file() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("advent-rs")?;
cmd.arg("--year").arg("2015");
cmd.arg("--day").arg("01");
cmd.arg("non_existing_file");
cmd.assert().failure().stderr(predicates::str::contains(
"advent-rs: No such file or directory",
));

Ok(())
}

#[test]
fn calls_a_proper_test() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("advent-rs")?;
Expand Down

0 comments on commit 3e1cfb0

Please sign in to comment.