{"record":{"id":"e8ada147b7439a8a","repo":"gofiber/fiber","slug":"errsharedstoragenotconfigured","errorCode":"ErrSharedStorageNotConfigured","errorMessage":"fiber: shared storage is not configured","messagePattern":"fiber: shared storage is not configured","errorType":"error_code","errorClass":null,"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/a105acad6c1e4576a77f01e02973f67e962bb58d/shared_state.go#L1-L35","documentation":"SharedState coordinates state across Fiber instances via a Storage backend. ErrSharedStorageNotConfigured is returned when SharedState methods are called before a Storage has been wired in (the storage field is nil).","triggerScenarios":"Calling app.SharedState().Get/Set (or any SharedState method) when the app was created without configuring Config.AppName / a Storage backend, or before passing a Storage to SharedState.","commonSituations":"Forgetting to wire Storage in production; using SharedState in unit tests without setup; multi-instance deployment expecting shared state while still using the in-process default.","solutions":["Configure a Storage backend when creating the app (e.g., Redis for production, memory for single-instance dev).","Assert SharedState is non-nil and has storage before the first call.","Wire Storage explicitly via the app config rather than relying on defaults."],"exampleFix":"// before\napp := fiber.New()\napp.SharedState().Set(\"k\", \"v\") // ErrSharedStorageNotConfigured\n\n// after\nstore := memory.New()\napp := fiber.New(fiber.Config{SharedState: &SharedState{Storage: store}})\napp.SharedState().Set(\"k\", \"v\")","handlingStrategy":"validation","validationCode":"if app.SharedState() == nil || !hasStorage(app) {\n    return fiber.NewError(fiber.StatusServiceUnavailable, \"shared state unavailable\")\n}","typeGuard":"func hasStorage(app *fiber.App) bool {\n    // wire Storage in fiber.Config at construction; assert before first call\n    return app != nil && /* Storage field set */ true\n}","tryCatchPattern":null,"preventionTips":["Configure Storage when creating the app, not after.","Use Redis (or equivalent) for multi-instance, memory for single-instance dev.","Assert SharedState is wired in a startup health check."],"tags":["shared-state","config","storage"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}