fix(prompt): return errors from functions that silently ignore API failures#868
fix(prompt): return errors from functions that silently ignore API failures#868AdeshDeshmukh wants to merge 1 commit into
Conversation
…ailures
8 functions in pkg/prompt/prompt.go discarded API errors using the blank
identifier (_) or log.Fatal, causing nil pointer panics when Harbor API
calls failed. Now they return (value, error) following the established
GetProjectNameFromUser/GetWebhookFromUser pattern.
Fixed functions:
- GetRegistryNameFromUser → (int64, error)
- GetReferenceFromUser → (string, error)
- GetImmutableTagRule → (int64, error)
- GetTagFromUser → (string, error)
- GetScannerIdFromUser → (string, error)
- GetInstanceFromUser → (string, error)
- GetMemberIDFromUser → (int64, error)
- GetQuotaIDFromUser → (int64, error)
Each uses a result{value, error} channel pattern (identical to
GetProjectNameFromUser) to propagate errors out of goroutines.
Function variables added for testability follow the project's
established mocking pattern (member_handler_test.go).
All 25 call sites across 20 files now check the returned error
and surface clear messages (e.g., "failed to list scanners").
Closes goharbor#684.
Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
|
@AdeshDeshmukh First of all, Thank you for showing interest in addressing the issue regarding the error handling. For you notice, I have been into it for a long time and there has been some discussion with the community regarding addition of Since I have been working related to it and the PR contains major changes in the function signatures and logic across the project, It will be conflicting with my work and would be hard for me to manage. So I would like to pursue it, hope you understand. Thank you. |
|
Thanks for the heads up, and apologies for any overlap — I should have checked #635/#636 more carefully before starting. That said, this is a focused bug fix (nil panics from I'm happy to:
No attachment to the PR — just wanted the panics fixed. I'll leave it to maintainers to decide how to proceed. |
|
Yeah, I can understand. The changes need to studied and let us leave it to the maintainers, but I have few reviews. |
vg006
left a comment
There was a problem hiding this comment.
I don't find any valid reason to declare aliases for the functions of the api package. They can be directly used.
|
closing this Since this overlaps with the ongoing work on #636 Thanks for the contribution though. |
Description
Fixes 8 functions in
pkg/prompt/prompt.gothat silently discarded Harbor API errors using the blank identifier (_), causing nil pointer panics when API calls fail. Also fixesGetQuotaIDFromUserwhich logged the error but still dereferenced a nil payload.Closes #684.
Before
After
Fixed Functions
Changes
pkg/prompt/prompt.go — 8 functions refactored to use result{value, error} channel pattern (same as existing GetProjectNameFromUser / GetWebhookFromUser). Function variables added for testability.
pkg/prompt/prompt_test.go — 9 new tests covering API failure and empty-list edge cases for all 8 functions.
25 caller sites across 20 files — each now checks the returned error with a clear message (e.g., "failed to list scanners").
Design Decisions
Type of Change
Testing
Signed-off-by: AdeshDeshmukh adeshkd123@gmail.com