fix: handle GetRobot error in robot create and update output path to prevent nil panic#928
Open
AdeshDeshmukh wants to merge 1 commit into
Open
Conversation
…prevent nil panic Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes nil pointer panics in robot create/update commands by handling errors from api.GetRobot() before saving formatted robot output.
Changes:
- Adds error handling for
api.GetRobot()in system robot create output path. - Adds error handling for
api.GetRobot()in system robot update output path. - Adds error handling for
api.GetRobot()in project robot create output path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cmd/harbor/root/robot/update.go |
Handles GetRobot errors before saving updated robot output. |
cmd/harbor/root/robot/create.go |
Handles GetRobot errors before saving created robot output. |
cmd/harbor/root/project/robot/create.go |
Handles GetRobot errors before saving created project robot output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three instances where
api.GetRobot()error was silentlydiscarded with
_, causing a nil pointer panic when the callfails in the
-o jsonor-o yamloutput path.Fixes #927
Background
After a robot is created or updated, the code calls
GetRobot()to fetch the full
*models.Robotrepresentation for JSON/YAMLoutput. This is intentional —
CreateRobotonly returns*models.RobotCreated(a subset without permissions), so asecond call is needed.
However in all 3 affected files the error was discarded:
If
GetRobotfails (network error, auth timeout, server error),resis nil andres.Payloadcauses a nil pointer panic.The CLI crashes instead of returning a clean error message.
Files Changed
cmd/harbor/root/project/robot/create.gocmd/harbor/root/robot/create.gocmd/harbor/root/robot/update.goTotal: ~15 lines across 3 files.
Fix Applied (same pattern for all 3 locations)
Pattern Alignment
This fix follows the exact pattern already used in the codebase
for the same
api.GetRobot()call:cmd/harbor/root/project/robot/view.go:Uses
utils.ParseHarborErrorMsgconsistent with all otherAPI error handling in the same files.
Checklist
go build ./...passesgo vet ./...passesgit commit -s)