Skip to content

gh repo set-default --view breaks Unix standards - returns exit code 0 upon failure and prints error to stdout instead of stderr #9398

@HariSekhon

Description

@HariSekhon

Describe the bug

GitHub CLI command gh repo set-default --view returns exit code 0 and prints error to stdout instead of stderr when the default repo isn't set.

This breaks Unix command line standard behaviour and makes it hard to detect and script around error handling and recovery.

$ gh --version
gh version 2.42.1 (2024-01-15)
https://github.com/cli/cli/releases/tag/v2.42.1

I've tried with the newer version too, same result:

$ gh --version
gh version 2.53.0 (2024-07-17)
https://github.com/cli/cli/releases/tag/v2.53.0

Steps to reproduce the behavior

In a repo clone, especially a forked repo:

gh repo set-default --view
echo $?

outputs:

no default repository has been set; use `gh repo set-default` to select one
0

You can see it outputs to stdout in place where the repo name would be expected. This will easily break the scripts of people expecting standard unix command line behaviour:

gh repo set-default --view 2>/dev/null

outputs to stdout instead of stderr:

no default repository has been set; use `gh repo set-default` to select one

although in a pipe this actually returns no output which is slightly easier to catch in script than testing for an error message which might change:

gh repo set-default --view | cat

returns no output:

Expected vs actual behavior

Expected it to exit code 1 if throwing an error such as no default repository has been set

Expected it to print the error to stderr instead of stdout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-reporelating to the gh repo commandhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions