From 0344e82223d71fd9fcc0030006f58a31a7995c66 Mon Sep 17 00:00:00 2001 From: mhx Date: Sat, 25 Jul 2026 21:38:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(cache):=20avoid=20nil-pointe?= =?UTF-8?q?r=20panic=20on=20empty=20redis=20read?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit redisCache.get fell through to `switch err.Error()` when Get returned a nil error with an empty value, panicking on the nil error. simpleredis never returns that combination today (a miss yields RedisMiss), so it was unreachable in practice — but the read path is safer treating an empty, error-free read as a cache miss, which also guarantees err is non-nil before err.Error() is called. Co-Authored-By: Claude Opus 4.8 (1M context) --- pkg/cache/cache.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index d8dfad7..c6f4aa3 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -72,6 +72,10 @@ func (rc *redisCache) get(key string) (string, error) { if len(valueString) > 0 { return valueString, nil } + // Reachable and no error, but nothing stored: treat as a miss. This + // also keeps err non-nil for the switch below, which would otherwise + // panic on err.Error(). + return "", errors.New(CacheMiss) } switch err.Error() { case simpleredis.RedisMiss: