Skip to content

[bug]: project robot list can panic instead of returning an error #862

@cotishq

Description

@cotishq

Description

harbor project robot list logs errors from project lookup or robot listing but continues execution. This can cause a nil pointer panic instead of returning a clean CLI error.

The issue is in cmd/harbor/root/project/robot/list.go.

Steps to Reproduce

  1. Run the command with an invalid or inaccessible project name:
harbor project robot list does-not-exist

2.Or trigger an API error while listing robots for a project.
3. Observe that the command can continue after the error and dereference a nil/invalid response.

Expected Behavior

The command should return immediately with a clear error message, for example:

failed to get project: <harbor error>

The CLI should exit with a non-zero status without panicking.

Actual Behavior

The command logs the error but continues execution.

Relevant code:

project, err := api.GetProject(args[0], false)
if err != nil {
    log.Errorf("Invalid Project Name: %v", err)
}
opts.ProjectID = int64(project.Payload.ProjectID)

If api.GetProject() fails, project.Payload may be nil and the command can panic.

A similar pattern exists after api.ListRobot(opts):

robots, err := api.ListRobot(opts)
if err != nil {
    log.Errorf("failed to get robots list: %v", err)
}

list.ListRobots(robots.Payload)

Environment

  • OS: Fedora linux
  • Tool version:
  • Other relevant details:

Additional Context

Command Run:

env XDG_CONFIG_HOME=/tmp/harbor-cli-verify/config \
    XDG_DATA_HOME=/tmp/harbor-cli-verify/data \
    ./harbor-cli project robot list does-not-exist

observed output:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions