Skip to content

fix(retention): prevent failures in tag retention rule deletion flow#996

Open
gcharpe1604 wants to merge 1 commit into
goharbor:mainfrom
gcharpe1604:fix/tag-retention-deletion-safety
Open

fix(retention): prevent failures in tag retention rule deletion flow#996
gcharpe1604 wants to merge 1 commit into
goharbor:mainfrom
gcharpe1604:fix/tag-retention-deletion-safety

Conversation

@gcharpe1604

Copy link
Copy Markdown
Contributor

Type of Change

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

Description / Quick Summary

This PR safeguards the tag retention rule deletion flow against unhandled errors. By propagating errors from API calls and prompt handlers up to Cobra's RunE boundary, the CLI now exits gracefully when rule lists are empty, when API calls fail, or when the user cancels the interactive prompt.


Problem

  • What issue exists?
    • prompt.GetRetentionTagRule() would block indefinitely on connection failures and did not return errors to its caller.
    • The deletion command assumed retention rules were always found, resulting in potential errors when indexing empty payloads.
    • api.DeleteRetention() executed redundant network lookups to resolve project names to retention IDs when the ID was already available.
  • Who is affected? Users attempting to view or delete tag retention rules when network/connection problems occur, or when no retention rules are configured on the project.
  • Current Behavior: The CLI could exit unexpectedly, block, or fail to surface actionable errors to the user.
  • Desired Behavior: All errors should propagate gracefully up to Cobra, printing user-friendly error messages and exiting with code 1.

Root Cause

  • Relevant Files:
    • cmd/harbor/root/tag/retention/delete.go
    • pkg/api/retention_handler.go
    • pkg/prompt/prompt.go
    • pkg/views/retention/select/view.go
  • Technical Explanation:
    The command and API wrapper layers did not check return errors from api.ListRetention() and did not propagate the error up to the Cobra RunE boundary.

Solution

  • Overview:
    1. Updated prompt.GetRetentionTagRule signature to return (int, error) and check for empty rules.
    2. Simplified DeleteRetention to use the already-available retention ID and removed a redundant lookup request.
    3. Propagated selection aborts and API errors up to cmd/harbor/root/tag/retention/delete.go.

Scope

Included

  • Returning errors from GetRetentionTagRule and propagating them in the delete command.
  • Optimizing DeleteRetention client helper to use direct ID.

Explicitly Not Included

  • Core selection model modification (no changes are made to pkg/views/base/selection/model.go to keep this PR strictly isolated).

Changes

  • cmd/harbor/root/tag/retention/delete.go: Added error check for prompt.GetRetentionTagRule and updated api.DeleteRetention invocation to use the direct retention ID.
  • pkg/api/retention_handler.go: Simplified DeleteRetention signature to accept retentionID directly and removed the redundant call to GetRetentionId.
  • pkg/prompt/prompt.go: Refactored GetRetentionTagRule to return (int, error) and added checks for API errors and empty rule lists.
  • pkg/views/retention/select/view.go: Refactored RetentionList to return (int, error) and propagate selection errors.

Testing

Unit Tests

  • All existing package tests pass (go test ./...)

Manual Verification

  1. Configured local dummy server.
  2. Ran .\harbor_retention.exe tag retention delete --project <project_name>.
  3. Observed the graceful exit and correct error reporting on connection refusal.

Risks & Compatibility

  • Backward Compatibility: Non-breaking. Enhances error propagation without changing successful prompt behavior.
  • Potential Risks: None identified.

Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.17%. Comparing base (60ad0bd) to head (5083ca6).
⚠️ Report is 187 commits behind head on main.

Files with missing lines Patch % Lines
pkg/views/retention/select/view.go 0.00% 11 Missing ⚠️
pkg/prompt/prompt.go 0.00% 7 Missing ⚠️
cmd/harbor/root/tag/retention/delete.go 0.00% 4 Missing ⚠️
pkg/api/retention_handler.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #996      +/-   ##
=========================================
- Coverage   10.99%   9.17%   -1.83%     
=========================================
  Files         173     321     +148     
  Lines        8671   16085    +7414     
=========================================
+ Hits          953    1475     +522     
- Misses       7612   14476    +6864     
- Partials      106     134      +28     

☔ View full report in Codecov by Harness.
📢 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Errors not propagated in tag retention rule deletion flow

1 participant