Skip to content

panic: reflect: call of reflect.Value.Interface on zero Value when gh pr view --json stateReason #9160

Description

@Frederick888

Describe the bug

$ gh --version
gh version 2.50.0 (2024-05-29)
https://github.com/cli/cli/releases/tag/v2.50.0
$ gh pr view --json stateReason
panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface({0x0?, 0x0?, 0x0?}, 0x0?)
        reflect/value.go:1501 +0xfb
reflect.Value.Interface(...)
        reflect/value.go:1496
github.com/cli/cli/v2/api.(*PullRequest).ExportData(0xc00066d188, {0xc000958990, 0x1, 0xc0008bf438?})
        github.com/cli/cli/v2/api/export_pr.go:144 +0x968
github.com/cli/cli/v2/pkg/cmdutil.(*jsonExporter).exportData(0xc0003a4480, {0x10bdd3cc0?, 0xc00066d188?, 0xc00079cfc0?})
        github.com/cli/cli/v2/pkg/cmdutil/json_flags.go:259 +0x52a
github.com/cli/cli/v2/pkg/cmdutil.(*jsonExporter).exportData(0xc0003a4480, {0x10bd23e60?, 0xc00066d188?, 0x109915c45?})
        github.com/cli/cli/v2/pkg/cmdutil/json_flags.go:239 +0x3ac
github.com/cli/cli/v2/pkg/cmdutil.(*jsonExporter).Write(0xc0003a4480, 0xc000429e40, {0x10bd23e60, 0xc00066d188})
        github.com/cli/cli/v2/pkg/cmdutil/json_flags.go:205 +0x11c
github.com/cli/cli/v2/pkg/cmd/pr/view.viewRun(0xc000644600)
        github.com/cli/cli/v2/pkg/cmd/pr/view/view.go:121 +0x3f5
github.com/cli/cli/v2/pkg/cmd/pr/view.NewCmdView.func1(0xc00069c008, {0xc00049ebc0, 0x0, 0x10a8a9242?})
        github.com/cli/cli/v2/pkg/cmd/pr/view/view.go:69 +0x349
github.com/spf13/cobra.(*Command).execute(0xc00069c008, {0xc00049eba0, 0x2, 0x2})
        github.com/spf13/[email protected]/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc000459808)
        github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        github.com/spf13/[email protected]/command.go:1048
main.mainRun()
        github.com/cli/cli/v2/cmd/gh/main.go:119 +0x53b
main.main()
        github.com/cli/cli/v2/cmd/gh/main.go:46 +0x13

Steps to reproduce the behavior

  1. Check out or submit a PR
  2. gh pr view --json stateReason
  3. See error

Expected vs actual behavior

Expected: It prints out a JSON with stateReason.

Actual: gh crashes.

Logs

(See above)

Activity

  1. williammartin commented on Jun 3, 2024

    @williammartin
    Member

    Hey @Frederick888, thanks for raising this issue, definitely a bug. I thought I checked this before merging #9080 but I think I just read the code and didn't try it out which was my mistake. Fundamentally the problem is that PullRequests don't support a "state reason".

    The issue with the implementation here is that PRs are treated as a superset of Issues in parts of the code and so when we produce the list of allowed --json fields, we append a list of PR fields to Issue fields and later we remove some fields from the request. This is pretty janky and leads to bugs like this one. I'll fix this later today, thank you for the report.

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    gh-prrelating to the gh pr command
    and removed on Jun 3, 2024
  3. added 2 commits that reference this issue on Jun 13, 2024
  4. williammartin commented on Jul 10, 2024

    @williammartin
    Member

    Just capturing what I expect to happen when someone gets round to implementing this.

    Acceptance Criteria

    Given there is a PR with <ID>
    When I run gh pr view --json stateReason <ID>
    Then I see the error Unknown JSON field: "stateReason" followed by a list of the available fields.

    Extra Notes

    We should confirm that issue view --json stateReason continues to work as expected.

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

    bugSomething isn't workinggh-prrelating to the gh pr commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions