{"id":"93005badf5966dd6","repo":"gofiber/fiber","slug":"fiber-shared-storage-is-not-configured","errorCode":null,"errorMessage":"fiber: shared storage is not configured","messagePattern":"fiber: shared storage is not configured","errorType":"exception","errorClass":"ErrSharedStorageNotConfigured","httpStatus":null,"severity":"error","filePath":"shared_state.go","lineNumber":17,"sourceCode":"package fiber\n\nimport (\n\t\"context\"\n\t\"encoding/hex\"\n\t\"encoding/json\"\n\t\"encoding/xml\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/gofiber/utils/v2\"\n)\n\nconst defaultSharedStatePrefix = \"gofiber-shared-state-\"\n\nvar ErrSharedStorageNotConfigured = errors.New(\"fiber: shared storage is not configured\")\n\ntype SharedState struct {\n\tstorage        Storage\n\tjsonEncoder    utils.JSONMarshal\n\tjsonDecoder    utils.JSONUnmarshal\n\tmsgPackEncoder utils.MsgPackMarshal\n\tmsgPackDecoder utils.MsgPackUnmarshal\n\tcborEncoder    utils.CBORMarshal\n\tcborDecoder    utils.CBORUnmarshal\n\txmlEncoder     utils.XMLMarshal\n\txmlDecoder     utils.XMLUnmarshal\n\tprefix         string\n}\n\nfunc newSharedState(cfg *Config) *SharedState {\n\tif cfg == nil {\n\t\tcfg = &Config{}\n\t}","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/shared_state.go#L1-L35","documentation":"Declared as ErrSharedStorageNotConfigured in shared_state.go and returned by every SharedState method (Set/Get/SetJSON/Has/Delete/Reset/Close and their *WithContext variants) via ensureStorage when app.config.SharedStorage is nil. SharedState is a cross-instance key/value layer that requires a Storage backend (e.g. Redis, badger, memory) to function; without one there is nowhere to read or write.","triggerScenarios":"Calling app.SharedState().* (or app.State().SharedState equivalent) without having set Config.SharedStorage when constructing the App. Happens when developers assume State() and SharedState() are interchangeable — State() is in-process, SharedState() needs a configured backend.","commonSituations":"Adopting the SharedState API for multi-instance coordination and forgetting the Storage dependency; confusing fiber.New()'s per-request storage with SharedState; running tests without wiring a storage stub.","solutions":["Set Config.SharedStorage to a Storage implementation (e.g. redis.New(), arangodb.New(), memory.New()) when creating the App.","Guard callers: check the returned error and degrade gracefully (e.g. fall back to local State()) if shared state is optional.","For tests, inject an in-memory storage so SharedState methods don't error."],"exampleFix":"// before\napp := fiber.New()\napp.SharedState().Set(ctx, \"k\", v, ttl) // returns ErrSharedStorageNotConfigured\n\n// after\napp := fiber.New(fiber.Config{\n    SharedStorage: redis.New(redis.Config{Addr: \":6379\"}),\n})\napp.SharedState().SetWithContext(ctx, \"k\", v, ttl)","handlingStrategy":"validation","validationCode":"// Wire Config.SharedStorage at App construction time.\napp := fiber.New(fiber.Config{\n    SharedStorage: redis.New(redis.Config{Addr: \":6379\"}),\n})","typeGuard":null,"tryCatchPattern":"if err := app.SharedState().SetWithContext(ctx, \"k\", v, ttl); err != nil {\n    if errors.Is(err, fiber.ErrSharedStorageNotConfigured) {\n        // shared state unavailable — degrade to in-process State() or fail gracefully\n        return nil\n    }\n    return err\n}","preventionTips":["Always set Config.SharedStorage when you intend to use SharedState().","Don't confuse State() (per-process) with SharedState() (cross-instance, needs Storage).","In tests, inject an in-memory Storage to satisfy SharedState callers."],"tags":["shared-state","storage","config"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}