{"id":"70a9641c5bb2fe5b","repo":"gofiber/fiber","slug":"cache-failed-to-get-raw-key-q-from-storage-w","errorCode":null,"errorMessage":"cache: failed to get raw key %q from storage: %w","messagePattern":"cache: failed to get raw key %q from storage: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/cache/manager.go","lineNumber":145,"sourceCode":"\t}\n\n\tif value := m.memory.Get(key); value != nil {\n\t\tit, ok := value.(*item)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"cache: unexpected entry type %T for key %q\", value, m.logKey(key))\n\t\t}\n\t\treturn it, nil\n\t}\n\n\treturn nil, errCacheMiss\n}\n\n// get raw data from storage or memory\nfunc (m *manager) getRaw(ctx context.Context, key string) ([]byte, error) {\n\tif m.storage != nil {\n\t\traw, err := m.storage.GetWithContext(ctx, key)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cache: failed to get raw key %q from storage: %w\", m.logKey(key), err)\n\t\t}\n\t\tif raw == nil {\n\t\t\treturn nil, errCacheMiss\n\t\t}\n\t\treturn raw, nil\n\t}\n\n\tif value := m.memory.Get(key); value != nil {\n\t\traw, ok := value.([]byte)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"cache: unexpected raw entry type %T for key %q\", value, m.logKey(key))\n\t\t}\n\t\treturn raw, nil\n\t}\n\n\treturn nil, errCacheMiss\n}\n","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/cache/manager.go#L127-L163","documentation":"Thrown at middleware/cache/manager.go:145 by manager.getRaw() when the configured fiber.Storage backend returns a non-nil error from GetWithContext on the raw-bytes read path (used for cached response bodies / ETag payloads rather than the msgp item). Identical in cause to error 140 but on the raw read API.","triggerScenarios":"A cached route or internal helper calls getRaw while Storage is configured and the backend GET fails: connection lost, query error, or the request context is cancelled before the storage returns.","commonSituations":"Redis/DB backend down or flapping; ctx cancelled because the client disconnected; storage driver misconfigured (wrong URL, expired credentials); network partition.","solutions":["Read the wrapped driver error to identify the root cause (connectivity, auth, timeout) and resolve it at the backend.","Health-check the storage endpoint at startup and on deploys so a bad config fails fast instead of at request time.","Tune the storage driver's timeout / pool to ride through brief outages.","Add a fiber.ErrorHandler that logs the raw-storage failure and serves an uncached response so users aren't blocked.","Ensure the per-request context has a deadline longer than the storage read timeout to avoid spurious context.DeadlineExceeded."],"exampleFix":"// before\nstore := redis.New() // default 0 timeout\n\n// after: explicit read timeout + boot-time connectivity check\nstore := redis.New(redis.Config{\n    URL:       os.Getenv(\"REDIS_URL\"),\n    ReadTimeout: 2 * time.Second,\n})\nctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\ndefer cancel()\nif _, err := store.GetWithContext(ctx, \"healthcheck\"); err != nil && !errors.Is(err, storage.ErrNotFound) {\n    log.Fatalf(\"cache storage unhealthy: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Boot-time connectivity probe for the raw read path.\nctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)\ndefer cancel()\nif _, err := store.GetWithContext(ctx, \"__raw_probe__\"); err != nil {\n    log.Fatalf(\"cache raw storage unhealthy: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"raw, err := m.storage.GetWithContext(ctx, key)\nif err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        return nil, errCacheMiss // client gave up; degrade\n    }\n    log.Printf(\"raw storage read failed: %v\", err)\n    return nil, err\n}","preventionTips":["Health-check storage at startup and on deploy.","Tune storage read timeout under the request deadline.","Monitor backend GET error rate; alert before users see failures.","Make raw-read failures degrade to an uncached response, not a 500."],"tags":["cache","storage","network","redis","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}