From cefbeba7591b4a86113dc36fbcbec1ce6c9cad20 Mon Sep 17 00:00:00 2001 From: zdiyax Date: Fri, 13 Mar 2026 23:39:11 +0500 Subject: [PATCH] fix(FindAllResources): handle single-object responses without panic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- service/config.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/service/config.go b/service/config.go index b863c4ad..7d4aeef0 100644 --- a/service/config.go +++ b/service/config.go @@ -737,14 +737,22 @@ func (c *NitroClient) FindAllResources(resourceType string) ([]map[string]interf c.logger.Trace(" FindAllResources: resource not found", "resourceType", resourceType) return make([]map[string]interface{}, 0, 0), nil } - resources := data[resourceType].([]interface{}) - - ret := make([]map[string]interface{}, len(resources), len(resources)) - for i, v := range resources { - ret[i] = v.(map[string]interface{}) + // The NITRO API returns a JSON array for most resource types, but a few + // (e.g. nsversion) return a single JSON object. Guard against the panic + // that occurs when the type assertion to []interface{} fails. + switch v := rsrcs.(type) { + case []interface{}: + ret := make([]map[string]interface{}, len(v)) + for i, item := range v { + ret[i] = item.(map[string]interface{}) + } + return ret, nil + case map[string]interface{}: + return []map[string]interface{}{v}, nil + default: + c.logger.Warn("FindAllResources: unexpected response shape", "resourceType", resourceType) + return make([]map[string]interface{}, 0, 0), nil } - - return ret, nil } // ResourceBindingExists returns true if the supplied binding exists