🐛 fix(cache): avoid nil-pointer panic on empty redis read

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) <noreply@anthropic.com>
This commit is contained in:
mhx
2026-07-25 21:38:03 +02:00
co-authored by Claude Opus 4.8
parent 73e53c7d69
commit 0344e82223
+4
View File
@@ -72,6 +72,10 @@ func (rc *redisCache) get(key string) (string, error) {
if len(valueString) > 0 { if len(valueString) > 0 {
return valueString, nil 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() { switch err.Error() {
case simpleredis.RedisMiss: case simpleredis.RedisMiss: