Skip to content

Commit 8df34dc

Browse files
committed
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".
1 parent 2dca95c commit 8df34dc

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

config/cache.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ 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

114119
count := response["count"]
115-
if response["api"] == nil {
116-
fmt.Println("Error: empty API list received, sync failed")
117-
return nil
118-
}
119120
apiList := response["api"].([]interface{})
120121

121122
for _, node := range apiList {

0 commit comments

Comments
 (0)