Skip to content

Panic in gh pr view --comments due to nil pointer dereference in project items #12325

Closed

Description

@chrishenzie

Describe the bug

When running gh pr view <number> --comments, the CLI panics with a runtime error: invalid memory address or nil pointer dereference.

This occurs in api/queries_projects_v2.go when processing projectItems. It appears the GraphQL API is returning null nodes in the projectItems connection, which the client does not check before dereferencing.

I observed this even when using a personal access token with full read-only access to all scopes, so I don't think this is a permission issue.

Affected version

$ gh version
gh version 2.83.1-68-g51dfeeaa7 (2025-12-16)
https://github.com/cli/cli/releases/latest

Steps to reproduce the behavior

$ gh pr view 5475 --repo kubernetes/enhancements
⡿panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x84fbaa]

goroutine 102 [running]:
github.com/cli/cli/v2/api.ProjectsV2ItemsForPullRequest(0xc00006ff60, {0x25b5320, 0xc0002490b0}, 0xc00085d008)
        github.com/cli/cli/v2/api/queries_projects_v2.go:179 +0x3aa
github.com/cli/cli/v2/pkg/cmd/pr/shared.(*finder).Find.func5()
        github.com/cli/cli/v2/pkg/cmd/pr/shared/finder.go:295 +0x32
golang.org/x/sync/errgroup.(*Group).Go.func1()
        golang.org/x/[email protected]/errgroup/errgroup.go:93 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
        golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x95

Expected vs actual behavior

The gh CLI returns PR details.

See above for the actual behavior.

Activity

  1. added
    bug
    on Dec 16, 2025
  2. added
    needs-triage
    on Dec 16, 2025
  3. babakks commented on Dec 17, 2025

    @babakks
    Member

    Thanks for reporting this and the PR, @chrishenzie! 🍻

    I cannot reproduce it on my end, probably because you have access to private/internal projects associated with this PR that I don't have.

    gh version
    # gh version 2.83.2 (2025-12-10)
    # https://github.com/cli/cli/releases/tag/v2.83.2
    
    gh pr view 5475 --repo kubernetes/enhancements | cat 
    # title:  KEP-5474: Introduce WritableCgroups option
    # state:  OPEN
    # author: Divya063

    Can you please try upgrading to v2.83.2 (current latest) and run again? And if you still see failures please share these as well (redact where needed):

    • DEBUG=api gh pr view 5475 --repo kubernetes/enhancements
    • gh auth status --json hosts (to make sure your OAuth scopes are rightly set)

    I haven't yet fully reviewed your PR because I need to make sure about a some details. It's probably what you have already mentioned, the nil items, but the debug logs will help us better understand the problem and if should be fixed in other commands.

  4. added
    more-info-needed
    gh-pr
    on Dec 17, 2025
  5. chrishenzie commented on Dec 17, 2025

    @chrishenzie
    ContributorAuthor

    Thanks for taking a look @babakks . I downloaded the latest release and tested again with that version.

    $ ./gh_2.83.2_linux_amd64/bin/gh version
    gh version 2.83.2 (2025-12-10)
    https://github.com/cli/cli/releases/tag/v2.83.2

    Unfortunately, I still experience the same panic on this version. Please see this gist for the debug logs.

    $ ./gh_2.83.2_linux_amd64/bin/gh auth status --json hosts
    {
      "hosts": {
        "github.com": [
          {
            "state": "success",
            "active": true,
            "host": "github.com",
            "login": "chrishenzie",
            "tokenSource": "<REDACTED_HOME_DIR>/.config/gh/hosts.yml",
            "gitProtocol": "ssh"
          }
        ]
      }
    }
  6. andyfeller commented on Dec 22, 2025

    @andyfeller
    Contributor

    Thanks, @chrishenzie! It appears the projectItems field is returning a null node, which causes the panic trying to dereference within the following loop:

    {
      "data": {
        "repository": {
          "pullRequest": {
            "projectItems": {
              "totalCount": 1,
              "nodes": [
                null
              ],
              "pageInfo": {
                "hasNextPage": false,
                "endCursor": "MQ"
              }
            }
          }
        }
      }
    }

    for {
    var query response
    err := client.Query(repo.RepoHost(), "PullRequestProjectItems", &query, variables)
    if err != nil {
    return err
    }
    for _, projectItemNode := range query.Repository.PullRequest.ProjectItems.Nodes {
    items.Nodes = append(items.Nodes, &ProjectV2Item{
    ID: projectItemNode.ID,
    Project: ProjectV2ItemProject{
    ID: projectItemNode.Project.ID,
    Title: projectItemNode.Project.Title,
    },
    Status: ProjectV2ItemStatus{
    OptionID: projectItemNode.Status.StatusFragment.OptionID,
    Name: projectItemNode.Status.StatusFragment.Name,
    },
    })
    }

    Expand for the full debug log entry

    * Request at 2025-12-17 11:09:43.485672464 -0800 PST m=+1.034953786
    * Request to https://api.github.com/graphql
    > POST /graphql HTTP/1.1
    > Host: api.github.com
    > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
    > Authorization: token ████████████████████
    > Content-Length: 476
    > Content-Type: application/json
    > Graphql-Features: merge_queue
    > Time-Zone: America/Los_Angeles
    > User-Agent: GitHub CLI 2.83.2
    
    GraphQL query:
    query PullRequestProjectItems($endCursor:String$name:String!$number:Int!$owner:String!){repository(owner: $owner, name: $name){pullRequest(number: $number){projectItems(first: 100, after: $endCursor){totalCount,nodes{id,project{id,title},status:fieldValueByName(name: "Status"){... on ProjectV2ItemFieldSingleSelectValue{optionId,name}}},pageInfo{hasNextPage,endCursor}}}}}
    GraphQL variables: {"endCursor":null,"name":"enhancements","number":5475,"owner":"kubernetes"}
    
    ⢿< HTTP/2.0 200 OK
    < Access-Control-Allow-Origin: *
    < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
    < Content-Security-Policy: default-src 'none'
    < Content-Type: application/json; charset=utf-8
    < Date: Wed, 17 Dec 2025 19:09:43 GMT
    < Github-Authentication-Token-Expiration: 2026-03-16 11:17:08 -0700
    < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
    < Server: github.com
    < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
    < Vary: Accept-Encoding, Accept, X-Requested-With
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: deny
    < X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
    < X-Github-Request-Id: 3809:1B5F77:4E84C8E:5043225:6942FFF7
    < X-Ratelimit-Limit: 5000
    < X-Ratelimit-Remaining: 4992
    < X-Ratelimit-Reset: 1766002037
    < X-Ratelimit-Resource: graphql
    < X-Ratelimit-Used: 8
    < X-Xss-Protection: 0
    
    {
      "data": {
        "repository": {
          "pullRequest": {
            "projectItems": {
              "totalCount": 1,
              "nodes": [
                null
              ],
              "pageInfo": {
                "hasNextPage": false,
                "endCursor": "MQ"
              }
            }
          }
        }
      }
    }
    
    * Request took 395.025616ms
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x842fca]
    
    goroutine 116 [running]:
    github.com/cli/cli/v2/api.ProjectsV2ItemsForPullRequest(0xc000e8df60, {0x25a40e8, 0xc000b50ed0}, 0xc0006b3808)
            /home/runner/work/cli/cli/api/queries_projects_v2.go:179 +0x3aa
    github.com/cli/cli/v2/pkg/cmd/pr/shared.(*finder).Find.func5()
            /home/runner/work/cli/cli/pkg/cmd/pr/shared/finder.go:295 +0x32
    golang.org/x/sync/errgroup.(*Group).Go.func1()
            /home/runner/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:93 +0x50
    created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
            /home/runner/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x95
    

    I've opened #12356 as I suspect permissions are preventing this v2 project items to being returned, requiring the gh code to skip them gracefully like we do in a few other places.

  7. added
    priority-2
    and removed
    more-info-needed
    on Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-prneeds-triagepriority-2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions