Repository navigation
Open
Labels
blockedbugSomething isn't workingplatformProblems with the GitHub platform rather than the CLI clientpriority-3Affects a small number of users or is largely cosmetic
Description
Describe the bug
If stdout of the command is piped to /dev/null, or captured with Python's subprocess.PIPE, the exit code is 0 even when it should be 1. This can silently mask real failures.
Affected version
Please run gh version and paste the output below.
$ gh version
gh version 2.25.1 (2023-03-21)
https://github.com/cli/cli/releases/tag/v2.25.1
Steps to reproduce the behavior
- Set up GH_TOKEN with a classic personal access token which does not have SSO access to the repo in question.
- Run
gh pr list --author=@me > /dev/null - Run
echo $? - Observe that the exit status was 0, even though the command failed. The failure is silently hidden.
Expected vs actual behavior
gh pr list should exit with a non-zero status if authentication failed.
Logs
Paste the activity from your command line. Redact if needed.
Actual behavior:
$ gh pr list --author=@me
GraphQL: Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization. (repo_000)
Authorize in your web browser: <URL REDACTED>
$ echo $?
1
$ gh pr list --author=@me > /dev/null
$ echo $?
0
Expected behavior:
$ gh pr list --author=@me
GraphQL: Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization. (repo_000)
Authorize in your web browser: <URL REDACTED>
$ echo $?
1
$ gh pr list --author=@me > /dev/null
$ echo $?
1 # This is the issue. This command should exit with nonzero status when authentication fails.
Actual output with verbose logs:
$ export GH_DEBUG=true
$ gh pr list --author=@me > /dev/null
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-05-08 15:45:31.763844771 +0000 UTC m=+0.051044783
* Request to https://api.github.com/graphql
* Request took 382.484907ms
$ echo $?
0
Reacted by Babak K. Shandiz
Metadata
Metadata
Assignees
Labels
blockedbugSomething isn't workingplatformProblems with the GitHub platform rather than the CLI clientpriority-3Affects a small number of users or is largely cosmetic
Activity
sfc-gh-bhannel commentedon May 8, 2025
I confirmed that this reproduces on
2.72.0(the latest release):babakks commentedon May 8, 2025
Hi @sfc-gh-bhannel, Thanks for reporting this! 🙏
This is an interesting case. I tried to reproduce this issue and could get to the same error message, but the exit code is always
1, regardless of the/dev/nullredirection:Note that since you're applying the
--authoroption,ghis calling a different GQL query than what I'm hitting in the above excerpt. I'm not sure how yet, but maybe that's the reason we're getting different exit codes.Now, I need these pieces of information from you to further investigate this:
Could you please provide me with these?
sfc-gh-bhannel commentedon May 9, 2025
Thank you for looking at this issue @babakks. Here is the output of the commands you requested. The issue is still reproducing for me. The
--authorfilter is necessary to reproduce the issue.Note the last exit code is 0 - that is the issue.
williammartin commentedon May 9, 2025
Thanks for the swift response.
Can you please provide the output without piping to devnull but including
--author:I understand why you are getting a zero exit code with
--author=@me > /dev/null(because the search API is reporting no results since it doesn't have access to your repo - that is, unfortunately, how the API seems to work). What I'm surprised about is that you ever receive the SAML error when providing--author, even when not piping to dev null as you said in your original report:babakks commentedon May 9, 2025
Thanks for the details, @sfc-gh-bhannel!
I agree with @williammartin that you shouldn't see the SAML error.
But I'm a bit confused now that I'm looking at the trails, because the SAML error should be there on stderr (as with the debug logs). I think you're not reproducing the same error as you reported at the top. Maybe something is different with your environment now.
babakks commentedon May 20, 2025
@sfc-gh-bhannel, It's been a while, so I'm nudging you if there's an update/change on your side.
williammartin commentedon Oct 8, 2026
Hey @sfc-gh-bhannel,
Thanks for the report, and sorry this took a while to untangle. In #10951 (comment) I was confused about why we saw the SAML error but I reproduced this with a token that isn't authorised for a SAML protected org. I ran
gh pr list --author=@mein a clone with no default repo set:The SAML error doesn't come from listing PRs at all. It comes from a query
ghmakes to pick a repo from your git remotes (that's therepo_000alias). We only make that lookup whenghcan prompt.Prompting requires both stdin and stdout to be a terminal. When stdout is redirected, we skip the lookup and use the first remote. That's also why the
-Rruns above never showed the SAML error.As for the original issue, to reiterate, with
--author, the list itself uses the search API. It seems search quietly drops results from repos your token isn't authorised for. Soghgets an empty result, and no results exits0. I'm not sure what we can do about that since the API makes no distinction.