Skip to content

refactor: deduplicate scope error handling between api/client.go and project queries#12845

Merged
BagToad merged 1 commit intocli:trunkfrom
yuvrajangadsingh:refactor/deduplicate-scope-error-handling
Mar 5, 2026
Merged

refactor: deduplicate scope error handling between api/client.go and project queries#12845
BagToad merged 1 commit intocli:trunkfrom
yuvrajangadsingh:refactor/deduplicate-scope-error-handling

Conversation

@yuvrajangadsingh
Copy link
Contributor

Fixes #12823

Both api/client.go and pkg/cmd/project/shared/queries/queries.go had their own copy of requiredScopesFromServerMessage and the same INSUFFICIENT_SCOPES parsing logic. The existing code even had a TODO noting this: // TODO: this duplicates parts of generateScopesSuggestion.

This PR removes the duplicated functions from queries.go and has handleError call api.GenerateScopeErrorForGQL instead. The duplicate test was also removed since api/client_test.go already covers requiredScopesFromServerMessage.

Changes:

  • queries.go: replaced handleError internals with a call to api.GenerateScopeErrorForGQL, removed requiredScopesFromServerMessage and scopesRE
  • queries_test.go: removed Test_requiredScopesFromServerMessage (covered by api/client_test.go:TestRequiredScopesFromServerMessage)
  • api/client.go: removed the now-resolved TODO comment

@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Mar 5, 2026
@yuvrajangadsingh yuvrajangadsingh marked this pull request as ready for review March 5, 2026 08:41
@yuvrajangadsingh yuvrajangadsingh requested a review from a team as a code owner March 5, 2026 08:41
@yuvrajangadsingh yuvrajangadsingh requested a review from babakks March 5, 2026 08:41
…project queries

Consolidate duplicated INSUFFICIENT_SCOPES error handling into a single
implementation. The project queries package now calls
api.GenerateScopeErrorForGQL instead of reimplementing the same logic.

Removes duplicated requiredScopesFromServerMessage, scopesRE, and the
associated test (already covered by api/client_test.go).

Fixes cli#12823
@yuvrajangadsingh yuvrajangadsingh force-pushed the refactor/deduplicate-scope-error-handling branch from 897346f to fdd6388 Compare March 5, 2026 15:28
Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and saw the same behavior between trunk and this PR - proper scope error message generation. LGTM

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 needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplicate scope error handling between api/client.go and project queries

2 participants