Skip to content

[bug]: password command: ignored GetCredentials error leads to fatal exit #742

@AMAN-sharma07

Description

@AMAN-sharma07

Description

When running the password command, the code ignores the error returned by GetCredentials and proceeds with a zero-value credential. UpdateCredentialsInConfigFile then calls log.Fatalf(...) when it cannot find the credential, causing the CLI to exit immediately (hard fatal) instead of returning a controlled error.

Steps to Reproduce

  1. Run command: go build -o harbor ./cmd/harbor
  2. Edit your Harbor config so current-credential-name is set to a name that does not exist in the credentials list (or otherwise remove the named credential).
  3. Run the password change: ./harbor password --old-password oldpass --new-password newpass
  4. Observe the process terminates with a fatal exit instead of returning a normal CLI error.

Expected Behavior

The password command should return a descriptive error if the current credential cannot be found and exit gracefully with a non-zero code (no abrupt process termination).
Helper functions (e.g., UpdateCredentialsInConfigFile, AddCredentialsToConfigFile) should return errors instead of calling log.Fatalf, allowing callers to handle/report failures.

Actual Behavior

UpdatePassword ignores the error from GetCredentials (existingCred, _ := utils.GetCredentials(...)) and builds a credential from zero-value fields.
UpdateCredentialsInConfigFile logs a fatal error (log.Fatalf("credential with name '%s' not found", ...)) and terminates the process immediately

Environment

  • OS: Linux
  • Go: go1.24.8 linux/amd64
  • Tool version: local build from this repository (no release tag)
  • Repo/branch: local workspace (include commit/branch when filing remotely)

Additional Context

This is triggered by stale or incorrect current-credential-name or by removing/mutating the named credential in the config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions