Skip to content

fix(FindAllResources): handle single-object responses without panic#106

Open
writesz wants to merge 1 commit intonetscaler:mainfrom
writesz:fix/find-all-resources-single-object
Open

fix(FindAllResources): handle single-object responses without panic#106
writesz wants to merge 1 commit intonetscaler:mainfrom
writesz:fix/find-all-resources-single-object

Conversation

@writesz
Copy link
Copy Markdown

@writesz writesz commented Mar 13, 2026

The NITRO API returns a JSON array for most resource types, but some (e.g. nsversion) return a single JSON object. The hard type assertion on line 740:

resources := data[resourceType].([]interface{})

panics with "interface conversion: interface {} is map[string]interface {}, not []interface {}" when the value is a plain object.

Replace the assertion with a type switch that handles:

  • []interface{} → existing array path (unchanged behaviour)
  • map[string]interface{} → wrap in a single-element slice
  • anything else → return empty slice with a warning log

The NITRO API returns a JSON array for most resource types, but some
(e.g. nsversion) return a single JSON object. The hard type assertion
on line 740:

    resources := data[resourceType].([]interface{})

panics with "interface conversion: interface {} is map[string]interface {},
not []interface {}" when the value is a plain object.

Replace the assertion with a type switch that handles:
  - []interface{}         → existing array path (unchanged behaviour)
  - map[string]interface{} → wrap in a single-element slice
  - anything else          → return empty slice with a warning log
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.

1 participant