Skip to content

GetRegistryIdByName returns (0, nil) for non-existent registry; callers delete or operate on ID 0 #933

@sahu-virendra-1908

Description

@sahu-virendra-1908

Problem

GetRegistryIdByName returns (0, nil) when no registry matches the provided name.

return 0, err

At this point err is already nil, so callers interpret the result as success and continue operating on registry ID 0.

Impact

Commands like:

harbor registry delete does-not-exist

silently call:

DELETE /registries/0

instead of returning a user-facing error.

This creates:

  • confusing UX
  • silent invalid API requests
  • potential wrong-resource operations

Affected Areas

  • cmd/harbor/root/registry/delete.go
  • cmd/harbor/root/registry/update.go
  • cmd/harbor/root/replication/policies/create.go

Root Cause

GetRegistryIdByName returns:

return 0, err

after iterating all registries without finding a match.

Since err == nil, callers receive (0, nil).

Expected Behavior

When a registry name is not found:

return 0, fmt.Errorf("registry with name %q not found", registryName)

should be returned.

Reproduction

harbor registry delete does-not-exist

Expected:

Error: registry with name "does-not-exist" not found

Actual:

DELETE /registries/0

(or Harbor API 404 response)

Proposed Fix

  1. Return explicit error from GetRegistryIdByName
  2. Remove ignored errors (_) in callers
  3. Properly propagate errors to users

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