Don't error on list commands when no results found (#5479)

Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
Roshan Padaki 2022-04-25 13:55:52 -04:00 committed by GitHub
parent adc9abd5ee
commit 13342cb272
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 178 additions and 201 deletions

View file

@ -203,6 +203,7 @@ func mainRun() exitCode {
if cmd, err := rootCmd.ExecuteC(); err != nil {
var pagerPipeError *iostreams.ErrClosedPagerPipe
var noResultsError cmdutil.NoResultsError
if err == cmdutil.SilentError {
return exitError
} else if cmdutil.IsUserCancellation(err) {
@ -216,6 +217,12 @@ func mainRun() exitCode {
} else if errors.As(err, &pagerPipeError) {
// ignore the error raised when piping to a closed pager
return exitOK
} else if errors.As(err, &noResultsError) {
if cmdFactory.IOStreams.IsStdoutTTY() {
fmt.Fprintln(stderr, noResultsError.Error())
}
// no results is not a command failure
return exitOK
}
printError(stderr, err, cmd, hasDebug)