Skip to content

fix: clarify scope error while creating issues for projects#12596

Open
elijahthis wants to merge 3 commits intocli:trunkfrom
elijahthis:fix/clarify-scope-error
Open

fix: clarify scope error while creating issues for projects#12596
elijahthis wants to merge 3 commits intocli:trunkfrom
elijahthis:fix/clarify-scope-error

Conversation

@elijahthis
Copy link

@elijahthis elijahthis commented Feb 1, 2026

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

  • Modified handleResponse to intercept GraphQL errors and check for INSUFFICIENT_SCOPES types.
  • Implemented GenerateScopeErrorForGQL to extract specific required scopes from the API response message.
  • Added requiredScopesFromServerMessage using regex to parse scope requirements (e.g., project, repo) from the server's text.

Note

I basically replicated the logic being used for queries (handleError found in pkg/cmd/project/shared/queries/queries.go)
image

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):

error: your authentication token is missing required scopes [project]
To request it, run:  gh auth refresh -s project

Test plan

  • Added test cases for newly-created functions
  • All existing tests pass

Fixes #12585

@elijahthis elijahthis requested a review from a team as a code owner February 1, 2026 22:34
@elijahthis elijahthis requested a review from babakks February 1, 2026 22:34
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 1, 2026
@BagToad
Copy link
Member

BagToad commented Feb 3, 2026

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? 🙏

@elijahthis
Copy link
Author

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!

@elijahthis
Copy link
Author

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 !

@BagToad BagToad self-requested a review February 4, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing error message on scopes

3 participants