Skip to content

Commit 2218325

Browse files
Fix nil panic in UpdateCache when listapisresponse is empty (#211) (#217)
* Fix nil panic in UpdateCache when listapisresponse is empty (#211) * Keep existing API cache when listApis returns an empty response Move the nil guard above the cache reset so a failed sync no longer clears the in-memory API cache, and return 0 so 'cmk sync' prints "Discovered 0 APIs" instead of "Discovered <nil> APIs". --------- Co-authored-by: Boris Stoyanov <bss.stoyanov@gmail.com>
1 parent c3c3377 commit 2218325

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

config/cache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (c *Config) SaveCache(response map[string]interface{}) {
108108

109109
// UpdateCache uses auto-discovery data to update internal API cache
110110
func (c *Config) UpdateCache(response map[string]interface{}) interface{} {
111+
if response["api"] == nil {
112+
fmt.Fprintf(os.Stderr, "Error: empty API list received, sync failed. Existing API cache is kept.\n")
113+
return 0
114+
}
115+
111116
apiCache = make(map[string]*API)
112117
apiVerbMap = nil
113118

0 commit comments

Comments
 (0)