Skip to content

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

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

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.

Sign up for free to 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

1 participant