{"record":{"id":"6436dfd17e1d5562","repo":"gofiber/fiber","slug":"fiber-shared-state-s-s-is-not-configured","errorCode":null,"errorMessage":"fiber: shared state %s %s is not configured","messagePattern":"fiber: shared state (.+?) (.+?) is not configured","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared_state.go","lineNumber":405,"sourceCode":"\t\tdefer func() {\n\t\t\trecovered = recover()\n\t\t}()\n\n\t\terr = decoder(data, out)\n\t}()\n\n\tif recovered != nil {\n\t\treturn sharedStateCodecPanicError(\"decode\", format, recovered)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"fiber: failed to decode shared state %s value: %w\", format, err)\n\t}\n\n\treturn nil\n}\n\nfunc sharedStateCodecNotConfiguredError(format, direction string) error {\n\treturn fmt.Errorf(\"fiber: shared state %s %s is not configured\", format, direction)\n}\n\nfunc sharedStateCodecPanicError(operation, format string, recovered any) error {\n\tif err, ok := recovered.(error); ok {\n\t\treturn fmt.Errorf(\"fiber: failed to %s shared state %s value: %w\", operation, format, err)\n\t}\n\n\treturn fmt.Errorf(\"fiber: failed to %s shared state %s value: %v\", operation, format, recovered)\n}\n\nfunc (s *SharedState) storageKey(key string) (string, bool) {\n\tif key == \"\" {\n\t\treturn \"\", false\n\t}\n\n\treturn s.prefix + hex.EncodeToString(utils.UnsafeBytes(key)), true\n}\n","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/shared_state.go#L387-L423","documentation":"Returned by sharedStateCodecNotConfiguredError() when the requested codec function is nil. newSharedState() sets defaults for JSON and XML encoders/decoders, but MsgPack and CBOR are left nil unless the app supplies them via Config.MsgPackEncoder/Decoder or Config.CBOREncoder/Decoder. Calling the corresponding SharedState method therefore has no codec to invoke.","triggerScenarios":"Calling app.State().Shared().SetMsgPack/GetMsgPack without Config.MsgPackEncoder/Decoder set; or SetCBOR/GetCBOR without Config.CBOREncoder/Decoder set. The check fires before any encode/decode attempt, so no panic occurs.","commonSituations":"Adopting SharedState MsgPack/CBOR for performance without wiring the codec; assuming Fiber ships a default msgpack/cbor codec (it does not — only JSON and XML default); removing a codec config line during refactor.","solutions":["Provide Config.MsgPackEncoder/Decoder (e.g., shamaton/msgpack Marshal/Unmarshal) when using SetMsgPack/GetMsgPack.","Provide Config.CBOREncoder/Decoder (e.g., fxamacker/cbor Marshal/Unmarshal) when using SetCBOR/GetCBOR.","Alternatively, use the JSON or XML methods, which have built-in defaults.","Add a startup assertion that the needed codecs are non-nil."],"exampleFix":"// before — using msgpack without configuring the codec\napp := fiber.New(fiber.Config{\n    SharedStorage: storage,\n    // MsgPackEncoder/Decoder missing\n})\napp.State().Shared().SetMsgPack(\"k\", v, 0)\n// -> fiber: shared state msgpack encoder is not configured\n\n// after — wire the codec\napp := fiber.New(fiber.Config{\n    SharedStorage:     storage,\n    MsgPackEncoder:    msgpack.Marshal,\n    MsgPackDecoder:    msgpack.Unmarshal,\n})\napp.State().Shared().SetMsgPack(\"k\", v, 0)","handlingStrategy":"validation","validationCode":"// Assert at startup that the codecs you use are configured.\nfunc requireCodecs(app *fiber.App, useMsgPack, useCBOR bool) error {\n    cfg := app.Config()\n    if useMsgPack && (cfg.MsgPackEncoder == nil || cfg.MsgPackDecoder == nil) {\n        return errors.New(\"msgpack codec required but not configured\")\n    }\n    if useCBOR && (cfg.CBOREncoder == nil || cfg.CBORDecoder == nil) {\n        return errors.New(\"cbor codec required but not configured\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := app.State().Shared().SetMsgPack(k, v, ttl); err != nil {\n    if strings.Contains(err.Error(), \"is not configured\") {\n        log.Fatal(\"configure MsgPackEncoder/Decoder before using MsgPack shared state\")\n    }\n    return err\n}","preventionTips":["Wire MsgPackEncoder/Decoder and CBOREncoder/Decoder in Config when adopting those codecs.","Use JSON/XML methods if you do not want to supply a codec — they have defaults.","Add a startup assertion listing which codecs each route/handler needs."],"tags":["shared-state","codec","config","msgpack","cbor","configuration"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}