fix(cache): pretty-print cache envelope
Some checks failed
CI / auto-fix (push) Failing after 0s
CI / test (push) Failing after 3s
CI / auto-merge (push) Failing after 0s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 05:20:29 +00:00
parent fbf410e630
commit 248f542b08
2 changed files with 8 additions and 4 deletions

View file

@ -166,12 +166,12 @@ func (c *Cache) Set(key string, data any) error {
ExpiresAt: time.Now().Add(ttl),
}
entryResult := core.JSONMarshal(entry)
if !entryResult.OK {
return core.E("cache.Set", "failed to marshal cache entry", entryResult.Value.(error))
entryBytes, err := json.MarshalIndent(entry, "", " ")
if err != nil {
return core.E("cache.Set", "failed to marshal cache entry", err)
}
if err := c.medium.Write(path, string(entryResult.Value.([]byte))); err != nil {
if err := c.medium.Write(path, string(entryBytes)); err != nil {
return core.E("cache.Set", "failed to write cache file", err)
}
return nil

View file

@ -3,6 +3,7 @@
package cache_test
import (
"strings"
"testing"
"time"
@ -60,6 +61,9 @@ func TestCache_New_Good(t *testing.T) {
if err != nil {
t.Fatalf("Read failed: %v", err)
}
if !strings.Contains(raw, "\n \"data\":") {
t.Fatalf("expected pretty-printed cache entry, got %q", raw)
}
entry := readEntry(t, raw)
ttl := entry.ExpiresAt.Sub(entry.CachedAt)