From 015f302616101728d4808cf9b797cc0b2d982d81 Mon Sep 17 00:00:00 2001 From: HappySean Date: Wed, 10 Jun 2026 14:57:34 +0800 Subject: [PATCH] fix(cli): surface API cache write failures instead of silently re-syncing Cache.WriteConfig() errors were swallowed, so a failed expiry write made every subsequent invocation treat the spec cache as missing and re-sync ('No cached API spec, syncing...' on each call). Log the failure reason to stderr, and include the file path in the cbor cache write error. Co-Authored-By: Claude Fable 5 --- cli/api.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/api.go b/cli/api.go index 5cc48e7..6b03f4b 100644 --- a/cli/api.go +++ b/cli/api.go @@ -93,7 +93,12 @@ func cacheAPI(name string, api *API) { } Cache.Set(name+".expires", time.Now().Add(24*time.Hour)) - Cache.WriteConfig() + if err := Cache.WriteConfig(); err != nil { + // Without the persisted expiry, LoadCachedAPI treats the cache as + // missing and every subsequent invocation re-syncs the spec. + // Surface the reason on stderr instead of silently degrading. + LogError("Could not persist API cache expiry (next runs will re-sync): %s", err) + } b, err := cbor.Marshal(api) if err != nil { @@ -101,7 +106,7 @@ func cacheAPI(name string, api *API) { } filename := filepath.Join(getCacheDir(), name+".cbor") if err := os.WriteFile(filename, b, 0o600); err != nil { - LogError("Could not write API cache %s", err) + LogError("Could not write API cache %s (next runs will re-sync): %s", filename, err) } }