Skip to content

bug: GetRobot error discarded in robot create and update output path causing nil pointer panic #927

@AdeshDeshmukh

Description

@AdeshDeshmukh

Summary

The error returned by api.GetRobot() is silently discarded with _
in three command files. When GetRobot fails, the result is nil and
the immediate dereference of res.Payload causes a nil pointer panic,
crashing the CLI. This only triggers in the -o json or -o yaml
output path, making it easy to miss in normal testing.

Environment

  • Commit SHA: e23964a
  • Repository: goharbor/harbor-cli
  • Trigger: using -o json or -o yaml flag with robot create/update commands

Affected Files (3 locations, identical pattern)

File 1

cmd/harbor/root/project/robot/create.go — line 205

name := response.Payload.Name
res, _ := api.GetRobot(response.Payload.ID)  // error discarded
utils.SavePayloadJSON(name, res.Payload)       // PANIC if res is nil
return nil

File 2

cmd/harbor/root/robot/create.go — line 334

res, _ := api.GetRobot(response.Payload.ID)
utils.SavePayloadJSON(response.Payload.Name, res.Payload)
return nil

File 3

cmd/harbor/root/robot/update.go — line 590

res, _ := api.GetRobot(opts.ID)
utils.SavePayloadJSON(opts.Name, res.Payload)

Steps to Reproduce

  1. Login to a Harbor instance
  2. Create a robot account with JSON output: harbor project robot create -o json
  3. If GetRobot call fails (network error, auth expiration between calls),
    the CLI panics with a nil pointer dereference instead of returning a
    clean error.

Expected Behavior

GetRobot errors should be checked and returned with a user-friendly
error message, matching the pattern already used for the same
api.GetRobot() call in other commands.

Actual Behavior

CLI panics with nil pointer dereference, crashes.


Note

The same api.GetRobot() function is called with proper error handling
in the view and update commands (e.g., project/robot/view.go:93-95,
project/robot/update.go:110). The create and update output-format
paths are the only places where the error is discarded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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