Skip to content

gh cache list --json should output [] when no caches exist #9882

@pinelibg

Description

@pinelibg

Describe the feature or problem you’d like to solve

When using gh cache list --json <fields> in a repository without workflow caches, the command outputs a error message instead of JSON.

$ gh cache list --json id
No caches found in <repository name>

This behavior breaks JSON parsing in automated scripts since they expect valid JSON output and they need extra error handling.
For consistent JSON output format, the output should be [].

Proposed solution

When the --json option is used, gh cache list should retuan an empty JSON array ([]) to indicate no caches exist.

$ gh cache list --json id
[]

The text message should still be shown when running without the --json flag.

Additional context

  • gh version: gh version 2.60.1 (2024-10-25)

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-cacherelating to the gh cache command

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions