fix: clarify scope error while creating issues for projects#12596
fix: clarify scope error while creating issues for projects#12596
Conversation
|
Hey @elijahthis, thank you for the PR. It looks like there are some issues with the tests. Could you have a look at those and @ mention me when it's ready for review? 🙏 |
On it! |
|
Hii @BagToad seems GitHub Actions was down when I pushed the last time. Just pushed an empty commit and checks all pass. Ready for review ! |
|
Hi @BagToad |
|
Tested PR #12596 locally on Ubuntu 24.04 (linux/amd64) with Go 1.25.6. Commands run: Result: I also grepped the implementation: the missing-scope detection appears to rely on parsing the GraphQL error message text via This seems fine as a pragmatic fix, but it is potentially brittle if GitHub changes the wording. To reduce risk, it may be worth adding/keeping a regression test that uses the exact message shown in #12585 (including the |
There was a problem hiding this comment.
@elijahthis, apologies for the delay. The team has been busy.
Tested this locally and it works correctly for the exact error from #12585, multi-scope scenarios, and non-scope errors. Approving as-is. I've opened #12823 to track deduplicating the scope error handling between api/client.go and queries.go - I do think we should do this at some point or at least document why it's not possible or practical.
@elijahthis, if you want to take a stab at that cleanup I've opened that issue up for contributing.
|
Hey @elijahthis, this PR appears to have introduced a regression that is now tracked in #12904. The issue: After rewriting, the error says: The ignorable-error check no longer matches, so an optional Call chain: #12845 (cc @yuvrajangadsingh) further refactored this path but inherited the same issue. Suggested fix: The simplest correct fix would be to move Alternatively, a typed |
|
@camjac251 good catch, yeah #12845 inherited this. opened #12913 to fix it, just removes the GenerateScopeErrorForGQL call from handleResponse so the original GraphQLError flows through to ProjectsV2IgnorableError. project commands still handle scope errors through their own handleError. |
|
Hey @elijahthis, I've reverted this PR in #12915 because it unfortunately resulted in a pretty bad bug. Don't worry about it though, it was the result some nasty fragile code far away in the codebase that you never could have predicated, and was even hard to catch for us in review. I've reopened the original issue. |
When a GraphQL query fails with INSUFFICIENT_SCOPES, the GitHub API error message tells users to visit token settings, which is unhelpful for OAuth users. This adds a scopes suggestion to GraphQLError (matching the pattern already used by HTTPError) that prints "gh auth refresh -s <scope>" after the error. Unlike the reverted PR cli#12596, this does NOT rewrite the original error message. The suggestion is stored separately on GraphQLError and printed by the top-level error handler. This preserves the original error text so ProjectsV2IgnorableError can still match against it, avoiding the regression that caused the revert.
Summary
Enhanced GraphQL error handling to provide more user-friendly and actionable messages when a token lacks the necessary permissions. Instead of a verbose technical trace, users now receive a concise list of missing scopes and a direct command to resolve the issue via gh auth refresh.
Changes
Note
I basically replicated the logic being used for queries (

handleErrorfound inpkg/cmd/project/shared/queries/queries.go)Example
Before (Raw GraphQL Trace):
GraphQL: Your token has not been granted the required scopes to execute this query. The 'addProjectV2ItemById' field requires one of the following scopes: ['project'], but your token has only been granted the: ['gist', 'read:org', 'read:project', 'repo', 'workflow'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens.Now (Clean CLI Error):
Test plan
Fixes #12585