Skip to content

Make GITHUB_TOKEN optional - #22

Merged
mre merged 4 commits into
lycheeverse:masterfrom
pawroman:github-token-optional
Oct 26, 2020
Merged

mre merged 4 commits into
lycheeverse:masterfrom
pawroman:github-token-optional

Conversation

@pawroman

Copy link
Copy Markdown
Member

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.

Comment thread src/checker.rs Resolved
Comment thread README.md Outdated
### CLI return codes

- `0` for success (all links checked successfully or excluded/skipped as configured)
- `1` for any failures

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be true for other errors bubbled up to main() (such as invalid value for --method)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pawroman pawroman Oct 26, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/checker.rs Resolved
Comment thread src/main.rs Outdated
None
};

if cfg.github_token.is_none() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()),

Comment thread src/options.rs Outdated
pub base_url: Option<String>,

#[structopt(
short,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😉

@pawroman pawroman Oct 26, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the short option makes sense to me 👍

@mre

mre commented Oct 25, 2020

Copy link
Copy Markdown
Member

Sorry, I merged in #23 so you might have to reintegrate master. 😅
Added some comments. Let me know what you think. Otherwise PR looks good.

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.
@pawroman
pawroman force-pushed the github-token-optional branch from c5450b7 to 92c1443 Compare October 26, 2020 21:25
@pawroman

Copy link
Copy Markdown
Member Author

Sorry, I merged in #23 so you might have to reintegrate master. sweat_smile
Added some comments. Let me know what you think. Otherwise PR looks good.

Addressed the comments now and rebased against master.

Comment thread src/checker.rs

// 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think there's a way to specify an epsilon. 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. There are some workarounds, but nothing built-in. 😬

Comment thread src/main.rs
/// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this behavior.

Comment thread src/main.rs

match success {
true => Ok(ExitCode::Success as i32),
false => Ok(ExitCode::LinkCheckFailure as i32),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey that's kinda cool!

Comment thread tests/cli.rs
.stdout(contains("Successful: 0"))
.stdout(contains("Errors: 0"));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are all great!

@mre

mre commented Oct 26, 2020

Copy link
Copy Markdown
Member

Good work my sir. Chapeau. 🥂🧐🎩

@mre
mre merged commit 326683f into lycheeverse:master Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants