Skip to content

Fix nil panic in UpdateCache when listapisresponse is empty (#211) - #217

Open
rohanmishra29 wants to merge 1 commit into
apache:mainfrom
rohanmishra29:fix-211-nil-panic-on-empty-listapisresponse
Open

Fix nil panic in UpdateCache when listapisresponse is empty (#211)#217
rohanmishra29 wants to merge 1 commit into
apache:mainfrom
rohanmishra29:fix-211-nil-panic-on-empty-listapisresponse

Conversation

@rohanmishra29

Copy link
Copy Markdown

Fixes#211

Problem

When the CloudStack management server returns an empty listapisresponse (i.e., {"listapisresponse":{}}), the sync command panics with:
panic: interface conversion: interface {} is nil, not []interface {}
This happens in config/cache.go at the type assertion response["api"].([]interface{}) when response["api"] is nil.

Fix

Added a nil check for response["api"] before the type assertion. If the API list is empty, the function now returns nil with a clear error message instead of panicking.

Testing

Built successfully with go build ./.... The nil check prevents the panic when an empty listapisresponse is received.

@borisstoyanov
borisstoyanov marked this pull request as ready for review August 6, 2026 10:11
CopilotAI lite review requested due to automatic review settings August 6, 2026 10:11
@borisstoyanovborisstoyanov added this to the 6.6.0 milestone Aug 6, 2026
@borisstoyanov

Copy link
Copy Markdown
Contributor

@rohanmishra29 thanks for this fix, I'll include it in the milestone

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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"] in Config.UpdateCache to prevent a panic on empty listapisresponse.
  • Print an error message and return early when the API list is missing.
File summaries
FileDescription
config/cache.goAdds 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.

Comment threadconfig/cache.go
Comment on lines 114 to +118
count := response["count"]
if response["api"] == nil {
fmt.Println("Error: empty API list received, sync failed")
return nil
}
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync cmd errors listapisresponse is empty

3 participants

@rohanmishra29@borisstoyanov