Skip to content

fix(registry): return error when registry name not found#955

Open
sahu-virendra-1908 wants to merge 1 commit into
goharbor:mainfrom
sahu-virendra-1908:fix/registry-id-by-name-not-found
Open

fix(registry): return error when registry name not found#955
sahu-virendra-1908 wants to merge 1 commit into
goharbor:mainfrom
sahu-virendra-1908:fix/registry-id-by-name-not-found

Conversation

@sahu-virendra-1908
Copy link
Copy Markdown

Description

Fixes an issue where GetRegistryIdByName returned (0, nil) when a registry name did not exist.

Previously, callers interpreted the result as success and continued operating on registry ID 0, causing commands like:

harbor registry delete does-not-exist

to incorrectly call:

DELETE /registries/0

This change now returns a proper error when the registry is not found and propagates the error correctly in the delete command.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Return explicit error when registry name is not found in GetRegistryIdByName
  • Handle and propagate errors correctly in registry/delete.go
  • Prevent invalid operations on registry ID 0

@sahu-virendra-1908
Copy link
Copy Markdown
Author

@bupd @Vad1mo @OrlinVasilev Please review this PR when you have time. I’ve addressed the issue by returning a proper error when the registry name is not found and by propagating the error correctly in the delete flow.

If any additional changes or improvements are needed, please let me know. Thanks

Copy link
Copy Markdown
Collaborator

@qcserestipy qcserestipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! In principle LGTM, please fix the small suggestions

registryID, _ := api.GetRegistryIdByName(arg)
registryID, err := api.GetRegistryIdByName(arg)
if err != nil {
return err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return a formated err that also parses the upstream harbor error message. There is utils.ParseHarborErrorMsg that you can use


return 0, err
return 0, fmt.Errorf(
"registry with name %q not found",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the format of these new lines

also use utils.ParseHarborErrorMsg

@qcserestipy qcserestipy added the Changes Requesed feedback that must be addressed before merging. label May 25, 2026
@qcserestipy
Copy link
Copy Markdown
Collaborator

Please also fix your failing DCO check

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.27%. Comparing base (60ad0bd) to head (7f1f09b).
⚠️ Report is 163 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/registry/delete.go 0.00% 3 Missing ⚠️
pkg/api/registry_handler.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #955      +/-   ##
=========================================
- Coverage   10.99%   9.27%   -1.72%     
=========================================
  Files         173     290     +117     
  Lines        8671   14601    +5930     
=========================================
+ Hits          953    1354     +401     
- Misses       7612   13121    +5509     
- Partials      106     126      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requesed feedback that must be addressed before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants