Fix nil panic in UpdateCache when listapisresponse is empty (#211) - #217
Fix nil panic in UpdateCache when listapisresponse is empty (#211)#217rohanmishra29 wants to merge 1 commit into
Conversation
|
@rohanmishra29 thanks for this fix, I'll include it in the milestone |
There was a problem hiding this comment.
🟡 Changes recommended
The new early-return path can still produce confusing CLI output and may wipe existing in-memory caches before validation, so the error handling should be adjusted to be safe and consistent.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR addresses a crash in CloudMonkey’s API discovery/cache update path when the CloudStack listApis response contains an empty listapisresponse (missing the api field), by adding a guard before the []interface{} type assertion.
Changes:
- Add a nil check for
response["api"]inConfig.UpdateCacheto prevent a panic on emptylistapisresponse. - Print an error message and return early when the API list is missing.
File summaries
| File | Description |
|---|---|
config/cache.go |
Adds a guard in UpdateCache to avoid panicking when listApis returns an empty response payload. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
| count := response["count"] | ||
| if response["api"] == nil { | ||
| fmt.Println("Error: empty API list received, sync failed") | ||
| return nil | ||
| } |
Fixes #211
Problem
When the CloudStack management server returns an empty
listapisresponse(i.e.,{"listapisresponse":{}}), thesynccommand panics with:panic: interface conversion: interface {} is nil, not []interface {}
This happens in
config/cache.goat the type assertionresponse["api"].([]interface{})whenresponse["api"]is nil.Fix
Added a nil check for
response["api"]before the type assertion. If the API list is empty, the function now returnsnilwith a clear error message instead of panicking.Testing
Built successfully with
go build ./.... The nil check prevents the panic when an emptylistapisresponseis received.