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 for GitHub API token permission failure #13988

Closed
jacktose opened this issue Oct 10, 2022 · 2 comments · Fixed by #14523
Closed

Improve error message for GitHub API token permission failure #13988

jacktose opened this issue Oct 10, 2022 · 2 comments · Fixed by #14523
Assignees
Labels
features New features help wanted We want help addressing this outdated PR was locked due to age

Comments

@jacktose
Copy link
Sponsor Contributor

Provide a detailed description of the proposed feature

When brew gist-logs (and maybe others?) fails because of insufficient scope on the GitHub API token, the only feedback is Error: Not Found, which does not point toward the solution.

Probably, the output should use this message, from utils/github/api.rb#L175-L180:

Your #{what} credentials do not have sufficient scope!
Scopes required: #{needed_scopes}
Scopes present:  #{credentials_scopes}
#{CREATE_GITHUB_PAT_MESSAGE}

I'm not sure where that message is used, or why it's not used in this case.

What is the motivation for the feature?

# Create GH token with no perms
export HOMEBREW_GITHUB_API_TOKEN=ghp_hunter2
$ brew gist-logs -p gettext
Error: Not Found

# Add gist perm to token
$ brew gist-logs -p gettext
https://gist.github.com/0b08a0f9fe9e3897125f9b5770091c6e

Error: Not Found is frustratingly unhelpful. It took me some trial and error to find the solution.

How will the feature be relevant to at least 90% of Homebrew users?

It will not. It will be relevant to users who use certain GitHub-related features of Homebrew.

What alternatives to the feature have been considered?

None, as far as I know. Though similar messaging is apparently present in utils/github/api.rb#L175-L180.

And similar issues were addressed in:
Linuxbrew/legacy-linuxbrew/issues/673
Homebrew/legacy-homebrew/issues/39864
Homebrew/legacy-homebrew/pull/50410

@jacktose jacktose added the features New features label Oct 10, 2022
@Bo98
Copy link
Member

Bo98 commented Oct 10, 2022

We do have a general system already that works for just about anything else. For some reason the Gist API behaves differently like this. It's not normal for it to return 404 for things like that (unless accessing a private resource - which we're not), so it seems like a GitHub bug IMO. Particularly since x-accepted-oauth-scopes is also blank so it doesn't even suggest you have wrong scopes.

The best we could probably do is catch GitHub::API::HTTPNotFoundError around the GitHub.create_gist call in brew gist-logs and print a different message in that situation.

@MikeMcQuaid
Copy link
Member

The best we could probably do is catch GitHub::API::HTTPNotFoundError around the GitHub.create_gist call in brew gist-logs and print a different message in that situation.

This makes sense to me 👍🏻

@MikeMcQuaid MikeMcQuaid added the help wanted We want help addressing this label Oct 11, 2022
@issyl0 issyl0 self-assigned this Feb 6, 2023
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
features New features help wanted We want help addressing this outdated PR was locked due to age
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants