Repository navigation
Make GITHUB_TOKEN optional - #22
Conversation
| ### CLI return codes | ||
|
|
||
| - `0` for success (all links checked successfully or excluded/skipped as configured) | ||
| - `1` for any failures |
There was a problem hiding this comment.
This seems to be true for other errors bubbled up to main() (such as invalid value for --method)
There was a problem hiding this comment.
Good point. We could use a different exit codes for pure link errors and config errors.
Proposing 1 for link errors and 2 for config errors.
There was a problem hiding this comment.
Because of how it currently works in Rust (return 1 for any Result::Err bubbled up to main) and how the lychee code is structured, I propose we reverse that.
E.g. 1 for config errors and unexpected runtime errors, and 2 for link errors. Rationale: it's way simpler to bubble all "unexpected" errors to main using the Result enum and the ? operator and rely on Rust to exit the process with status code 1. Where we can control the status code easily without much effort, e.g. link errors, we can return 2.
This could be expanded to be 3 for specific config errors in the future, if need be, but it would require extra effort to classify errors and to normalize the ? handling in main()/run().
I will make the change to show what I mean; we can then discuss if it's OK with you.
| None | ||
| }; | ||
|
|
||
| if cfg.github_token.is_none() { |
There was a problem hiding this comment.
Guess the default use-case would be non-Github links so I'd remove that warning as it might be confusing. How about we extend the status message from above?
Right now it is
Status::Error("GitHub token not specified".to_string()),How about
Status::Error("GitHub token not specified. Use `--github-token` flag / `GITHUB_TOKEN` env var.".to_string()),| pub base_url: Option<String>, | ||
|
|
||
| #[structopt( | ||
| short, |
There was a problem hiding this comment.
Personally I'd remove the short option in case we'd like to support an option where -g is fitting. Can't think of anything right now but I'd rather keep the set of options small for now and make it quite explicit that we're passing a github token here.
I'm fine either way, though. 😉
There was a problem hiding this comment.
Removing the short option makes sense to me 👍
|
Sorry, I merged in #23 so you might have to reintegrate |
This also makes the token possible to pass in from CLI args.
The exit code is now defined as 1 for unexpected or config errors, and 2 for link check failures. GitHub checking behavior has been tweaked to generate errors if a GitHub-specific check cannot be performed because of a missing token.
c5450b7 to
92c1443
Compare
Addressed the comments now and rebased against master. |
|
|
||
| // on slow connections, this might take a bit longer than nominal backed-off timeout (7 secs) | ||
| assert!(end.as_secs() >= 7); | ||
| assert!(end.as_secs() <= 8); |
There was a problem hiding this comment.
Think there's a way to specify an epsilon. 🤔
There was a problem hiding this comment.
Nope. There are some workarounds, but nothing built-in. 😬
| /// A C-like enum that can be cast to `i32` and used as process exit code. | ||
| enum ExitCode { | ||
| Success = 0, | ||
| // NOTE: exit code 1 is used for any `Result::Err` bubbled up to `main()` using the `?` operator. |
There was a problem hiding this comment.
Thanks for documenting this behavior.
|
|
||
| match success { | ||
| true => Ok(ExitCode::Success as i32), | ||
| false => Ok(ExitCode::LinkCheckFailure as i32), |
| .stdout(contains("Successful: 0")) | ||
| .stdout(contains("Errors: 0")); | ||
| } | ||
|
|
|
Good work my sir. Chapeau. 🥂🧐🎩 |
This also makes the token possible to pass in from CLI args.
I got bitten by this a few times, and decided that issuing a warning instead of failing would be a better choice in terms of user experience.
Happy to tweak the behavior to if you think the new default is not an improvement over the old one.