Skip to content

Commit dde46dc

Browse files
maxbeizerCopilot
andcommitted
Add "Resource not accessible" to ProjectsV2IgnorableError
When a token (GitHub App, fine-grained PAT, or GITHUB_TOKEN) lacks the project permission, querying projectItems on a PR or issue fails with "Resource not accessible by integration" or "Resource not accessible by personal access token". ProjectsV2IgnorableError did not match these errors, causing commands like pr view, pr edit, and issue view to fail entirely instead of gracefully omitting project data. Add "Resource not accessible by" as an ignorable error prefix. This is safe because ProjectsV2IgnorableError is only called in project-specific code paths. Closes cli#13280 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ea7a245 commit dde46dc

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

api/queries_projects_v2.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
)
1010

1111
const (
12-
errorProjectsV2ReadScope = "field requires one of the following scopes: ['read:project']"
13-
errorProjectsV2UserField = "Field 'projectsV2' doesn't exist on type 'User'"
14-
errorProjectsV2RepositoryField = "Field 'projectsV2' doesn't exist on type 'Repository'"
15-
errorProjectsV2OrganizationField = "Field 'projectsV2' doesn't exist on type 'Organization'"
16-
errorProjectsV2IssueField = "Field 'projectItems' doesn't exist on type 'Issue'"
17-
errorProjectsV2PullRequestField = "Field 'projectItems' doesn't exist on type 'PullRequest'"
12+
errorProjectsV2ReadScope = "field requires one of the following scopes: ['read:project']"
13+
errorProjectsV2UserField = "Field 'projectsV2' doesn't exist on type 'User'"
14+
errorProjectsV2RepositoryField = "Field 'projectsV2' doesn't exist on type 'Repository'"
15+
errorProjectsV2OrganizationField = "Field 'projectsV2' doesn't exist on type 'Organization'"
16+
errorProjectsV2IssueField = "Field 'projectItems' doesn't exist on type 'Issue'"
17+
errorProjectsV2PullRequestField = "Field 'projectItems' doesn't exist on type 'PullRequest'"
18+
errorProjectsV2ResourceNotAccessible = "Resource not accessible by"
1819
)
1920

2021
type ProjectV2 struct {
@@ -321,18 +322,20 @@ func CurrentUserProjectsV2(client *Client, hostname string) ([]ProjectV2, error)
321322
}
322323

323324
// When querying ProjectsV2 fields we generally don't want to show the user
324-
// scope errors and field does not exist errors. ProjectsV2IgnorableError
325-
// checks against known error strings to see if an error can be safely ignored.
326-
// Due to the fact that the GraphQLClient can return multiple types of errors
327-
// this uses brittle string comparison to check against the known error strings.
325+
// scope errors, field does not exist errors, or authorization errors.
326+
// ProjectsV2IgnorableError checks against known error strings to see if an
327+
// error can be safely ignored. Due to the fact that the GraphQLClient can
328+
// return multiple types of errors this uses brittle string comparison to check
329+
// against the known error strings.
328330
func ProjectsV2IgnorableError(err error) bool {
329331
msg := err.Error()
330332
if strings.Contains(msg, errorProjectsV2ReadScope) ||
331333
strings.Contains(msg, errorProjectsV2UserField) ||
332334
strings.Contains(msg, errorProjectsV2RepositoryField) ||
333335
strings.Contains(msg, errorProjectsV2OrganizationField) ||
334336
strings.Contains(msg, errorProjectsV2IssueField) ||
335-
strings.Contains(msg, errorProjectsV2PullRequestField) {
337+
strings.Contains(msg, errorProjectsV2PullRequestField) ||
338+
strings.Contains(msg, errorProjectsV2ResourceNotAccessible) {
336339
return true
337340
}
338341
return false

api/queries_projects_v2_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ func TestProjectsV2IgnorableError(t *testing.T) {
317317
errMsg: "Field 'projectItems' doesn't exist on type 'PullRequest'",
318318
expectOut: true,
319319
},
320+
{
321+
name: "resource not accessible by integration",
322+
errMsg: "Resource not accessible by integration",
323+
expectOut: true,
324+
},
325+
{
326+
name: "resource not accessible by personal access token",
327+
errMsg: "Resource not accessible by personal access token",
328+
expectOut: true,
329+
},
330+
{
331+
name: "resource not accessible by integration with path context",
332+
errMsg: "GraphQL: Resource not accessible by integration (repository.pullRequest.projectItems.nodes.0)",
333+
expectOut: true,
334+
},
320335
{
321336
name: "other error",
322337
errMsg: "some other graphql error message",

0 commit comments

Comments
 (0)