goharbor / goharbor/harbor-cli

bug: silent `error-handling` in prompt functions

Open
#684 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

as I was working on #680 multiple functions in `pkg/prompt/prompt.go` silently ignore API errors using the blank identifier (`_`). This can cause nil pointer panics when API calls fail.

## Affected Functions (10 total)

| Line | Function | Issue |
|------|----------|-------|
| 51 | [GetRegistryNameFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:47:0-55:1) | `response, _ := api.ListRegistries()` |
| 160 | [GetReferenceFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:155:0-163:1) | `response, _ := api.ListArtifact(...)` |
| 170 | [GetUserIdFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:165:0-174:1) | `response, _ := api.ListUsers()` |
| 180 | [GetImmutableTagRule()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:176:0-183:1) | `response, _ := api.ListImmutable(...)` |
| 189 | [GetTagFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:185:0-192:1) | `response, _ := api.ListTags(...)` |
| 208 | [GetScannerIdFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:203:0-212:1) | `response, _ := api.ListScanners()` |
| 279 | [GetInstanceFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:274:0-283:1) | `response, _ := api.ListInstance()` |
| 322 | [GetRobotPermissionsFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:318:0-325:1) | `response, _ := api.GetPermissions()` |
| 336 | [GetRobotIDFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:327:0-339:1) | `response, _ := api.ListRobot(...)` |
| 395 | [GetMemberIDFromUser()](cci:1://file:///home/raashed/lfx/harbor-cli/pkg/prompt/prompt.go:389:0-406:1) | `response, _ := api.ListMembers(...)` |

## Impact

If an API call fails, `response` is nil and accessing `response.Payload` causes a **panic**.

## Proposed Fix

Follow the pattern used by `GetProjectNameFromUser()` and `GetWebhookFromUser()` which properly return errors.

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.