{"id":"eb3c6a8550d45ded","repo":"gofiber/fiber","slug":"fiber-failed-to-s-shared-state-s-value-w","errorCode":null,"errorMessage":"fiber: failed to %s shared state %s value: %w","messagePattern":"fiber: failed to (.+?) shared state (.+?) value: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared_state.go","lineNumber":410,"sourceCode":"\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":392,"sourceCodeEnd":423,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/shared_state.go#L392-L423","documentation":"Returned by sharedStateCodecPanicError (shared_state.go:410) when a configured shared-state encoder/decoder PANICS during operation and the recovered value implements the error interface. Fiber installs a recover() around the codec call (shared_state.go:357-359, 387-389) and converts the panic into a wrapped error so callers get a normal error instead of a crash. The message names the operation (encode/decode), the format, and wraps the recovered error.","triggerScenarios":"A custom or binder.Unimplemented* codec panics with an error value while serializing/deserializing shared state. The recover in encodeSharedStateValue/decodeSharedStateValue catches it and sharedStateCodecPanicError formats it because recovered.(error) succeeds.","commonSituations":"Using Fiber's binder.Unimplemented* placeholders that panic to signal 'not implemented'; a buggy custom encoder that panics on edge-case types; a codec library that panics on nil inputs instead of returning an error.","solutions":["Replace the panicking codec with a real implementation (msgpack/cbor/json) — the message indicates which format/direction panicked.","If using binder.Unimplemented* placeholders, wire the actual encoder/decoder in fiber.Config.","Audit your custom codec to return errors instead of panicking.","Read the wrapped error to find the panic message and offending codec."],"exampleFix":"// before: placeholder codec that panics\ncfg.MsgPackEncoder = binder.UnimplementedMsgPackMarshal\n\n// after: real codec\nimport \"github.com/vmihailenco/msgpack/v5\"\ncfg.MsgPackEncoder = msgpack.Marshal\ncfg.MsgPackDecoder = msgpack.Unmarshal","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := state.SetMsgPack(ctx, \"k\", v, ttl); err != nil {\n    if strings.Contains(err.Error(), \"failed to\") && strings.Contains(err.Error(), \"shared state\") {\n        // codec panicked — replace with a real implementation\n    }\n}","preventionTips":["Never use binder.Unimplemented* codecs in production.","Replace placeholder codecs with real implementations before going live.","Audit custom codecs to ensure they return errors, not panics."],"tags":["shared-state","codecs","panic","recover","binder"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}