Skip to content

fix(artifact): abort delete when project selection fails - #1104

Open
mantrapatel05 wants to merge 2 commits into
goharbor:mainfrom
mantrapatel05:fix/artifact-delete-swallowed-prompt-error
Open

mantrapatel05 wants to merge 2 commits into
goharbor:mainfrom
mantrapatel05:fix/artifact-delete-swallowed-prompt-error

Conversation

@mantrapatel05

Copy link
Copy Markdown
Contributor

Fixes #1102

In interactive mode, harbor artifact delete previously logged errors from GetProjectNameFromUser() and continued with an empty project name. This could lead to an API call with empty values and produce a confusing error.

The command now returns the project selection error immediately, matching the behavior of artifact label delete and repository delete. The unused logrus import was also removed.

Type of Change

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

Changes

  • Return the project selection error instead of logging and continuing.
  • Prevent deletion attempts when interactive project selection fails.
  • Remove the unused logrus import.

Tested

  • go test root.
  • Verified the argument-based delete path remains unchanged.

…ve delete

Signed-off-by: Mantra Patel <patelmantra551@gmail.com>
@mantrapatel05 mantrapatel05 changed the title fix: don't swallow project-selection error in artifact delete fix(artifact): abort delete when project selection fails Sep 27, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="cmd/harbor/root/artifact/delete.go">

<violation number="1" location="cmd/harbor/root/artifact/delete.go:41">
P2: Custom agent: **Enforce Pragmatic Test Coverage**

Add a regression test for the interactive `GetProjectNameFromUser()` error path and assert that `RunE` returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

projectName, err = prompt.GetProjectNameFromUser()
if err != nil {
log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Custom agent: Enforce Pragmatic Test Coverage

Add a regression test for the interactive GetProjectNameFromUser() error path and assert that RunE returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/harbor/root/artifact/delete.go, line 41:

<comment>Add a regression test for the interactive `GetProjectNameFromUser()` error path and assert that `RunE` returns the wrapped error without attempting artifact deletion. This changed failure behavior prevents a destructive API call and is not covered by the existing tests.</comment>

<file context>
@@ -39,7 +38,7 @@ func DeleteArtifactCommand() *cobra.Command {
 				projectName, err = prompt.GetProjectNameFromUser()
 				if err != nil {
-					log.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
+					return fmt.Errorf("failed to get project name: %v", utils.ParseHarborErrorMsg(err))
 				}
 				repoName = prompt.GetRepoNameFromUser(projectName)
</file context>

@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 9.83%. Comparing base (60ad0bd) to head (e5d8121).
⚠️ Report is 223 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #1104      +/-   ##
=========================================
- Coverage   10.99%   9.83%   -1.16%     
=========================================
  Files         173     326     +153     
  Lines        8671   16529    +7858     
=========================================
+ Hits          953    1626     +673     
- Misses       7612   14763    +7151     
- Partials      106     140      +34     

☔ 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.

Signed-off-by: Mantra Patel <patelmantra551@gmail.com>
@mantrapatel05

Copy link
Copy Markdown
Contributor Author

codecov/patch is at 100%. The codecov/project failure compares against a base report (60ad0bd) that's 223 commits behind main, so the drop looks inherited from main rather than from this PR. The branch is already rebased on current upstream/main. Happy to adjust if you'd like anything changed.

This branch has not been deployed

No deployments
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]: artifact delete proceeds with delete after interactive project selection fails or is cancelled

1 participant