Skip to content

gh label list --json prints nothing instead of [] when the repository has no labels #15066

Open

Agent suggestions

Public preview

Description

@mono0x

Describe the bug

gh label list --json prints nothing when the repository has no labels. I expected an empty JSON array ([]), like gh variable list --json prints when there are no variables.

The empty output cannot be parsed as JSON, causing scripts that expect JSON to fail.

Affected version

gh version 2.104.0 (2026-11-12)
https://github.com/cli/cli/releases/tag/v2.104.0

Steps to reproduce the behavior

  1. Pick a repository with no labels.
  2. Run gh label list --repo OWNER/REPO --json name,color,description; echo $?
  3. Nothing is printed to stdout, and the exit status is 0.

Expected vs actual behavior

Expected: [] is printed.

Actual: nothing is printed.

Logs

$ GH_DEBUG=api gh label list --repo mono0x/202611-gh-cli-test --json name,color,description; echo $?
* Request at 2026-11-17 00:25:02.025048 +0900 JST m=+0.013274501
* 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: 612
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: Asia/Tokyo
> User-Agent: GitHub CLI 2.104.0
> X-Github-Api-Version: 2022-11-28

GraphQL query:
fragment label on Label{name,color,description}
  query LabelList($owner: String!, $repo: String!, $limit: Int!, $endCursor: String, $query: String, $orderBy: LabelOrder) {
    repository(owner: $owner, name: $repo) {
      labels(first: $limit, after: $endCursor, query: $query, orderBy: $orderBy) {
        totalCount,
        nodes {
          ...label
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  }
GraphQL variables: {"limit":30,"orderBy":{"direction":"ASC","field":"CREATED_AT"},"owner":"mono0x","query":"","repo":"202611-gh-cli-test"}

⣟< 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, Warning
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Mon, 16 Nov 2026 15:25:02 GMT
< Github-Authentication-Token-Expiration: 2026-11-16 19:44:44 UTC
< 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-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Edge-Region: japaneast
< X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: 560E:186A2B:10552E:1A4AD2:6AFB204E
< X-Oauth-Client-Id: ...
< X-Oauth-Scopes:
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4993
< X-Ratelimit-Reset: 1794843665
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 7
< X-Xss-Protection: 0

{
  "data": {
    "repository": {
      "labels": {
        "totalCount": 0,
        "nodes": [],
        "pageInfo": {
          "hasNextPage": false,
          "endCursor": null
        }
      }
    }
  }
}

* Request took 671.448417ms
no labels found in mono0x/202611-gh-cli-test
0

$ GH_DEBUG=api gh variable list --repo mono0x/202611-gh-cli-test --json name; echo $?
* Request at 2026-11-17 00:25:05.581033 +0900 JST m=+0.013615751
* Request to https://api.github.com/repos/mono0x/202611-gh-cli-test/actions/variables?per_page=100
> GET /repos/mono0x/202611-gh-cli-test/actions/variables?per_page=100 HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Type: application/json; charset=utf-8
> Time-Zone: Asia/Tokyo
> User-Agent: GitHub CLI 2.104.0
> X-Github-Api-Version: 2022-11-28

< 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, Warning
< Cache-Control: private, max-age=60, s-maxage=60
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Mon, 16 Nov 2026 15:25:05 GMT
< Etag: W/"988058d477a27e2fe8e704bd6bec500341777e328edf9697cfe2e4bcb93fadf9"
< Github-Authentication-Token-Expiration: 2026-11-16 19:44:44 UTC
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Github-Permissions: actions_variables=read
< X-Accepted-Oauth-Scopes:
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-11-28
< X-Github-Edge-Region: japaneast
< X-Github-Media-Type: github.v3; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: DDF6:2574DA:12654B:1DE911:6AFB2051
< X-Oauth-Client-Id: ...
< X-Oauth-Scopes:
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4962
< X-Ratelimit-Reset: 1794843187
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 38
< X-Xss-Protection: 0

{
  "variables": [],
  "total_count": 0
}

* Request took 368.840584ms
[]
0

Activity

  1. cli-triage commented on Nov 16, 2026

    @cli-triage

    Reproducible on 2.104.0.

    Using test data for a repository with no labels:

    $ gh label list --repo example.invalid/hello --json name,color,description

    Output: none.

    Exit status: 0.

    The same empty output and success status occurred on the 2.104.0 release and source build source-4e71d58. The command should write [] when JSON output is requested so scripts always receive valid JSON. This differs from list commands that serialize an empty collection, and the current result requires callers to special-case an otherwise successful command.

    Supporting reports

    Generated by issue triage.

  2. added
    bug
    gh-label
    priority-3
    on Nov 16, 2026
  3. removed
    needs-triage
    on Nov 16, 2026
  4. babakks commented on Nov 17, 2026

    @babakks
    Member

    Thanks for your engagement on this, @mono0x and @deepak26ba! 🙏

    I agree that this behaviour is something unexpected, but I'm afraid altering it could be a breaking change, especially for when --search is used and there's no results. I can imagine, currently, users would script against the empty stdout as an indication of an empty list, and if it's not empty, they'd assume it's a non-empty array and attempt to access an element without prior checking.

    The PR is closed because it wasn't a help wanted Contributions welcome issue, and also the change of behaviour is not yet discussed by the team. If we ever decided to go with this change we'll consider reopening the PR.

  5. babakks commented on Nov 17, 2026

    @babakks
    Member

    I'm marking this as blocked while we investigate the compatibility impact. Returning valid JSON makes sense, but changing empty output to an empty array can break existing scripts, including some workflows we found. We need to decide whether we're comfortable proceeding with that behavior change before moving forward.

  6. added
    needs-investigation
    on Nov 17, 2026
  7. mono0x commented on Nov 17, 2026

    @mono0x
    Author

    @babakks
    Thank you for the detailed explanation. I understand that there are backward compatibility concerns with fixing this issue.

    On the other hand, there are cases where an empty string is returned when JSON is expected, and this causes problems. For example: babarot/gh-infra#322

    Even if it is hard to change this behavior in the short term, adding a note about it to the documentation might be one way to reduce these problems.

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

    blockedbuggh-labelneeds-investigationpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions