goharbor / goharbor/harbor-cli

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

Open
#933 1 comment 0 reactions 0 assignees View on GitHub
bug status/needs-feedback
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Problem

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

```go
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:

```bash
harbor registry delete does-not-exist
```

silently call:

```text
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:

```go
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:

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

should be returned.

## Reproduction

```bash
harbor registry delete does-not-exist
```

Expected:

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

Actual:

```text
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.