You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugSomething isn't workinggh-prrelating to the gh pr commandhelp wanted candidateIssue may be marked as help-wanted but not yet ready to accept PRpriority-3Affects a small number of users or is largely cosmetic
A clear and concise description of what the bug is. Include version by typing gh --version.
Version: 2.38.0 gh pr status throws a malformed error when the user is not logged in
edit: Even more puzzling, logging in doesn't fix the error because I have a $GITHUB_TOKEN set with incorrect permissions. CLI should detect this and tell the user that the token that they are logged in with does not have the correct permissions to execute the command they are attempting.
Steps to reproduce the behavior
log out
gh pr status
error: non-200 OK status code: 401 Unauthorized body: "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\"}"
Expected vs actual behavior
Expected: Print a correctly formatted error with a help message
Actual: prints a malformed error
Logs
Paste the activity from your command line. Redact if needed.
mono on alex/migrate-kinde-v2 [$!] via v18.17.1
❯ gh pr status
non-200 OK status code: 401 Unauthorized body: "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\"}"
mono on alex/migrate-kinde-v2 [$!] via v18.17.1
❯ gh pr view
HTTP 401: Bad credentials (https://api.github.com/graphql)
Try authenticating with: gh auth login
@alexng353 Thanks for writing in. I was able to reproduce this easily by running GH_TOKEN=test gh pr status. I agree we should output a nicely formatted error message as we do in other commands. I am going to open this up for community contributions.
@samcoe
Hi.
I have read the code about this and it seems that other commands have the same problem.
gh gist list
gh release list
etc.
api.NewClientFromHTTP(...) .Query(...) can all be reproduced.
The cause is that go-gh is not correctly handling the shurcooL/graphql errors it uses internally.
Since this error is not likely to be evaluated with errors.As() or errors.Is(), I think I will have to force it to be handled as follows.
Hi @williammartin (wasn't sure who to ping), I was checking this out and on on version gh version 2.74.2 (2025-06-18) this appears to be fixed for all core list commands. I think this can be closed.
@t4kamura sorry no one responded to you, Sam actually left GitHub shortly after his message and no one else was subscribed. I suspect the better option would be to ensure we capture this error in go-gh and wrap correctly so that gh can handle it like the other errors.
Ah, it only appears to be an issue when using GH_TOKEN, sorry, I didn't check with GH_TOKEN set.
❯ gh gist list
To get started with GitHub CLI, please run: gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.
❯ GH_TOKEN=test gh gist list
non-200 OK status code: 401 Unauthorized body: "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\",\"status\":\"401\"}"
I can see in gist list where it directly returns when token is set (pkg/cmd/gist/list/list.go L83). I guess we'd have to check each command individually to see which have malformed go-gh errors?
bugSomething isn't workinggh-prrelating to the gh pr commandhelp wanted candidateIssue may be marked as help-wanted but not yet ready to accept PRpriority-3Affects a small number of users or is largely cosmetic
Activity
jcasale commentedon Dec 9, 2023
I am now seeing something similar (exact same error as the
gh pr statuserror above) with 2.40.0.If I haveGH_TOKENorGITHUB_TOKENdefined, no command works.This was a red herring, my exact problem is now correctly identified in #8441.
samcoe commentedon Jan 11, 2024
@alexng353 Thanks for writing in. I was able to reproduce this easily by running
GH_TOKEN=test gh pr status. I agree we should output a nicely formatted error message as we do in other commands. I am going to open this up for community contributions.t4kamura commentedon Mar 17, 2024
@samcoe
Hi.
I have read the code about this and it seems that other commands have the same problem.
gh gist listgh release listetc.
api.NewClientFromHTTP(...) .Query(...)can all be reproduced.The cause is that go-gh is not correctly handling the shurcooL/graphql errors it uses internally.
Since this error is not likely to be evaluated with
errors.As()orerrors.Is(), I think I will have to force it to be handled as follows.cli/cmd/gh/main.go
Lines 158 to 166 in c0658b7
to
However, this is not smart, because it will not work if the GitHub API response changes, and it depends on the shurcooL/graphql specification.
I would like to ask the core team how to solve these problems. If I can handle it, I would like to do it.
What are your thoughts on these and other possible responses?
ale8k commentedon Jun 24, 2025
Hi @williammartin (wasn't sure who to ping), I was checking this out and on on version
gh version 2.74.2 (2025-06-18)this appears to be fixed for all core list commands. I think this can be closed.williammartin commentedon Jun 25, 2025
Seems to still indicate an issue.
williammartin commentedon Jun 25, 2025
@t4kamura sorry no one responded to you, Sam actually left GitHub shortly after his message and no one else was subscribed. I suspect the better option would be to ensure we capture this error in
go-ghand wrap correctly so thatghcan handle it like the other errors.ale8k commentedon Jun 25, 2025
Ah, it only appears to be an issue when using GH_TOKEN, sorry, I didn't check with GH_TOKEN set.
I can see in
gist listwhere it directly returns when token is set (pkg/cmd/gist/list/list.go L83). I guess we'd have to check each command individually to see which have malformedgo-gherrors?