Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when the repo is not found #128

Closed
crudiedo opened this issue Oct 4, 2022 · 3 comments · Fixed by #135
Closed

Improve error message when the repo is not found #128

crudiedo opened this issue Oct 4, 2022 · 3 comments · Fixed by #135
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.com/ help wanted Extra attention is needed output Fancy (and not so) output of the tool
Milestone

Comments

@crudiedo
Copy link
Contributor

crudiedo commented Oct 4, 2022

Currently, if we mistype owner/repo in the conf file, we get this error:

❌  bottom https://api.github.com/repos/clementtsang/notbottom/releases/tags/0.6.3: status code 404

It looks a bit confusing for the user since it looks like something tags\releases related.

I propose to:

  • Create new RepoError::NotFound(owner, repo) error and implement fmt::Display for it (something like "Repo {owner}/{repo} is not found, please check if it's available")
  • Send a head request to https://api.github.com/repos/{owner}/{repo} before calling fetch_release_info
  • Catch ureq::Error::Status(404, _) on the head request above and show RepoError instead

I believe this would also work for the repos that got deleted.

@chshersh chshersh added enhancement New feature or request help wanted Extra attention is needed output Fancy (and not so) output of the tool hacktoberfest https://hacktoberfest.com/ labels Oct 6, 2022
@chshersh
Copy link
Owner

chshersh commented Oct 6, 2022

The plan looks great to me! 👍🏻
The only problem, without the GitHub token, there's a quite limited number of requests a tool can do. If we add an extra request to fetch tools, it makes tool-sync less usable for such users.

So it makes sense to minimise the total number of requests as much as possible. I agree that it can be unavoidable sometimes to provide better UX but still.

My alternative proposal would be to submit a separate request to GitHub only if the releases/latest is not found. Every GitHub repo has the latest release (if it has at least one). Could we check if GitHub returns different results for:

  1. Wrong owner/repo
  2. Correct owner/repo without an releases

?

@crudiedo
Copy link
Contributor Author

crudiedo commented Oct 7, 2022

@chshersh thanks, it makes sense.

Regarding the different results - Github API always returns 404 with

{
    "message": "Not Found",
    "documentation_url": "https://docs.github.com/rest/reference/repos#get-the-latest-release"
}

no matter if you mistyped the repo or the tag.

I've also checked that on the repo with no releases and the latest tag, and got exactly the same error, so we won't be able to identify the reason based on the client.fetch_release_info() response only :(

I believe it would be a rare case when somebody wants to fetch a repo that has no releases at all, so we might want to avoid that check\separate request if the releases/latest tag is not found since, as you mentioned, it should exist for every repo.

I propose to do it this way then:

If client.fetch_release_info() returns 404 (the reason could be either repo or tag is not found)

  • and the tag is latest, show the The Repo is not found, please make sure the configuration is correct error
  • and the tag is anything else, show the Either repo or release is not available, please make sure the configuration is correct error

This way, we wouldn't make any additional requests, and also partially cover this #69 issue until we figure out something better.

@chshersh
Copy link
Owner

chshersh commented Oct 7, 2022

@crudiedo This sounds excellent to me 💯 And thanks for checking how the API works 👍🏻

My only suggestion is for the error message when the tag is latest: let's also mention that the repository might not have any releases:

-The Repo is not available, please make sure the owner and repo are correct
+The {owner}/{repo} doesn't exist or has no releases.

In theory, we could output a better error message when we see a GITHUB_TOKEN env variable. But it'll complicate the code significantly so let's just output messages that tell about potential multiple errors.

@chshersh chshersh added this to the v0.3.0: Auto milestone Oct 7, 2022
chshersh pushed a commit that referenced this issue Oct 11, 2022
…135)

Resolves #128

This PR adds a new error `RepoError::NotFound` and uses it when
fetch_release_info returns 404.

The error message depends on the tag, and could be either 
❌  **bottom** The clementtsang/bottomx doesn't exist or tags/0.66.3 was
not found.

or

❌  **bottom** The clementtsang/bottomx doesn't exist or has no releases.

if the tag is latest.

### Additional tasks

- [ ] Documentation for changes provided/changed
- [ ] Tests added
- [x] Updated CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.com/ help wanted Extra attention is needed output Fancy (and not so) output of the tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants