goharbor / goharbor/harbor-cli

Bug: Invalid --output-format returns exit code 0

Open
#1,100 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Description

When an invalid value is supplied to `--output-format`, several Harbor CLI commands log the formatting error but still return `nil`, causing the CLI to exit with status code `0`.

The affected commands are:

* `harbor info`
* `harbor labels list`
* `harbor registry list`
* `harbor repo list`
* `harbor user list`

## Steps to Reproduce

1. Run:

```bash
./harbor-cli user list --output-format=invalid; echo "exit_code=$?"
```

2. Observe the error:

```text
ERRO[0001] unable to output in the specified 'invalid' format
exit_code=0
```

3. Observe the exit code:

```text
0
```

The same behavior was also reproduced with:

```bash
./harbor-cli info --output-format=invalid
```

## Expected Behavior

The command should return a non-zero exit code when `utils.PrintFormat()` fails due to an invalid output format.

For example:

```text
ERRO[0000] unsupported output format: invalid
exit=1
```

This allows shell scripts and CI/CD pipelines to correctly detect the failure.

## Actual Behavior

The formatting error is logged, but the command returns `nil`, resulting in exit code `0`.

The affected commands follow this pattern:

```go
if formatFlag != "" {
err = utils.PrintFormat(data, formatFlag)
if err != nil {
log.Error(err)
}
}
return nil
```

In contrast, commands such as `harbor project list` propagate the error returned by `utils.PrintFormat()`.

## Environment

* OS: Linux
* Tool version: Local build from current `harbor-cli` main branch
* Other relevant details: Reproduced locally with an invalid `--output-format` value

Contributor guide

Open the contributing guide

Research direction

Start by locating the implementations of harbor info, labels list, registry list, repo list, and user list, then compare their utils.PrintFormat error handling with harbor project list. Reproduce the issue using ./harbor-cli user list --output-format=invalid and verify that each affected command returns a non-zero exit status when formatting fails. Done means the error is propagated consistently and regression coverage confirms the exit behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.