[bug]: artifact tags create and delete panic with index out of range when exactly one argument is provided
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start with the command definitions and RunE paths in cmd/harbor/root/artifact/tags/create.go and delete.go, especially the argument access identified in the issue. Verify the validator behavior for zero, one, two, and three or more arguments. Done means zero and two arguments retain their existing modes, invalid counts produce a clear Cobra error, and no panic or API call occurs.
Written by the indexing model from the issue text.
Description
Description
harbor artifact tags create and harbor artifact tags delete both panic with an index out of range error when called with exactly one argument.
Both commands support two modes:
- 0 arguments — launches interactive prompts to select project, repo, reference, and tag
- 2 arguments — takes
<reference>and<tag>directly, skips prompts
Neither command defines an Args validator on the cobra.Command. When a user passes exactly one argument, the code enters the non-interactive branch (because len(args) > 0 is true) and immediately accesses args[1], which does not exist. The CLI crashes instead of showing a usage error.
Steps to Reproduce
- Run
harbor artifact tags create myproject/myrepo/sha256:abc123(provides a reference but omits the tag name). - Alternatively, run
harbor artifact tags delete myproject/myrepo/sha256:abc123. - The CLI panics with a runtime index out of range error instead of exiting cleanly.
Expected Behavior
A clear error message explaining what is missing, printed by Cobra before any code in RunE executes:
Error: requires both <project>/<repository>/<reference> and <tag>, got only one argument
The CLI should exit with a non-zero status code and make no API calls.
Actual Behavior
The CLI crashes with:
panic: runtime error: index out of range 1 with length 1
goroutine 1 running:
[github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/tags.(*CreateTagsCmd...).RunE](https://github.com/goharbor/harbor-cli/cmd/harbor/root/artifact/tags.(*CreateTagsCmd...).RunE)(...)
cmd/harbor/root/artifact/tags/create.go:42
The crash originates at these lines in both cmd/harbor/root/artifact/tags/create.go:36-42 and delete.go:34-40:
if len(args) > 0 {
projectName, repoName, reference, err = utils.ParseProjectRepoReference(args[0])
if err != nil {
return fmt.Errorf("failed to parse project/repo/reference: %v", err)
}
tagName = args[1] // ← PANICS when len(args) == 1
} else {
// interactive prompt path
}
Environment
- OS: macOS / Linux / Windows (any)
- Harbor CLI version:
mainbranch - Harbor server version: N/A — the panic occurs locally before any API call is made
Additional Context
Why the simple fix won't work — The obvious fix, adding Args: cobra.ExactArgs(2), is incorrect here because both commands also support a 0-argument interactive mode. Using ExactArgs(2) would break the interactive prompt flow that already works correctly.
Proposed approach — Add a custom Args validator function that explicitly handles the argument count cases:
0 args: Allowed (launches interactive mode)2 args: Allowed (non-interactive execution)1or3+ args: Reject with a clear Cobra error message
This preserves the existing interactive functionality while preventing the panic and giving the user a clear, helpful error message.
Scope — Both create.go and delete.go in cmd/harbor/root/artifact/tags/ have the identical bug. A single pull request will fix both files, as they are in the same package (artifacttags) and share the same code pattern.
I believe a custom Args validator could work here , but I'm open to
other approaches if you have a different preference.
- Dominant language
- Go
- Stars
- 163
- Forks
- 212
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from goharbor/harbor-cli
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
goharbor/harbor-cli#1102 ·
-
[bug]: harbor webhook list cmd renders both interactive ui and json when format specified is json Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
goharbor/harbor-cli#1098 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
goharbor/harbor-cli#1096 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
goharbor/harbor-cli#1080 ·
-
bug status/has-approved-pr
Difficulty 1/5 Under an hour Newbie friendliness 90/100
goharbor/harbor-cli#1072 · 1 comment ·
All issues in goharbor/harbor-cli
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100