fix: improve error handling for aoc-cli errors
This commit is contained in:
parent
50d426a11b
commit
b9e6f8823d
2 changed files with 17 additions and 10 deletions
|
@ -162,7 +162,7 @@ To read inputs for previous years, append the `--year/-y` flag. _(example: `carg
|
|||
|
||||
### Download puzzle inputs via aoc-cli
|
||||
|
||||
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.6.0
|
||||
1. Install [`aoc-cli`](https://github.com/scarvalhojr/aoc-cli/) via cargo: `cargo install aoc-cli --version 0.7.0`
|
||||
2. Create an `.adventofcode.session` file in your home directory and paste your session cookie[^1] into it. To get this, press F12 anywhere on the Advent of Code website to open your browser developer tools. Look in your Cookies under the Application or Storage tab, and copy out the `session` cookie value.
|
||||
|
||||
Once installed, you can use the [download command](#download-input-for-a-day).
|
||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -133,16 +133,18 @@ pub mod aoc_cli {
|
|||
|
||||
pub enum AocCliError {
|
||||
CommandNotFound,
|
||||
CommandFailed,
|
||||
CommandNotCallable,
|
||||
BadExitStatus(Output),
|
||||
IoError,
|
||||
}
|
||||
|
||||
impl Display for AocCliError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AocCliError::CommandNotFound => write!(f, "CommandNotFound"),
|
||||
AocCliError::CommandFailed => write!(f, "CommandFailed"),
|
||||
AocCliError::IoError => write!(f, "IoError"),
|
||||
AocCliError::CommandNotFound => write!(f, "aoc-cli is not present in environment."),
|
||||
AocCliError::CommandNotCallable => write!(f, "aoc-cli could not be called."),
|
||||
AocCliError::BadExitStatus(_) => write!(f, "aoc-cli exited with a non-zero status."),
|
||||
AocCliError::IoError => write!(f, "could not write output files to file system."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,11 +183,16 @@ pub mod aoc_cli {
|
|||
);
|
||||
|
||||
let output = call_aoc_cli(&args)?;
|
||||
println!("---");
|
||||
println!("🎄 Successfully wrote input to \"{}\".", &input_path);
|
||||
println!("🎄 Successfully wrote puzzle to \"{}\".", &puzzle_path);
|
||||
|
||||
Ok(output)
|
||||
if output.status.success() {
|
||||
println!("---");
|
||||
println!("🎄 Successfully wrote input to \"{}\".", &input_path);
|
||||
println!("🎄 Successfully wrote puzzle to \"{}\".", &puzzle_path);
|
||||
Ok(output)
|
||||
} else {
|
||||
Err(AocCliError::BadExitStatus(output))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn get_input_path(day: u8) -> String {
|
||||
|
@ -221,6 +228,6 @@ pub mod aoc_cli {
|
|||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.map_err(|_| AocCliError::CommandFailed)
|
||||
.map_err(|_| AocCliError::CommandNotCallable)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue