{"id":"717b6edac51f07bc","repo":"gofiber/fiber","slug":"fiber-failed-to-s-shared-state-s-value-v","errorCode":null,"errorMessage":"fiber: failed to %s shared state %s value: %v","messagePattern":"fiber: failed to (.+?) shared state (.+?) value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared_state.go","lineNumber":413,"sourceCode":"\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":395,"sourceCodeEnd":423,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/shared_state.go#L395-L423","documentation":"Returned by sharedStateCodecPanicError (shared_state.go:413) when a configured shared-state encoder/decoder PANICS with a value that is NOT an error (e.g. a string, a custom struct). Because recovered.(error) fails, Fiber formats the panic value with %v rather than %w. The operation (encode/decode) and format are still named.","triggerScenarios":"A custom codec panics with panic(\"some string\") or panic(42) or panic(MyStruct{...}) instead of an error. The recover catches it, the type assertion to error fails (shared_state.go:409), so the %v branch at shared_state.go:413 fires.","commonSituations":"Hand-written codec that does panic(\"unsupported type\") instead of returning an error; a third-party library that panics with non-error values; misuse of panic with primitive types.","solutions":["Fix the custom codec to panic with errors, or better, return errors instead of panicking.","Replace the codec with a standard implementation that returns errors.","Inspect the %v string in the message to locate the offending panic site in your codec.","Add unit tests around the codec with the failing input type."],"exampleFix":"// before: codec panics with a string\nfunc badEnc(v any) ([]byte, error) {\n    if v == nil { panic(\"nil not allowed\") }\n    ...\n}\n\n// after: return an error\func badEnc(v any) ([]byte, error) {\n    if v == nil { return nil, errors.New(\"nil not allowed\") }\n    ...\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := state.SetMsgPack(ctx, \"k\", v, ttl); err != nil {\n    // a non-error panic value was recovered; inspect message %v text\n    log.Printf(\"codec panic: %v\", err)\n}","preventionTips":["Custom codecs should return errors, never panic with primitives.","Wrap any unavoidable panic values as errors via panic(fmt.Errorf(...)).","Unit-test codecs against nil and unsupported inputs."],"tags":["shared-state","codecs","panic","recover","custom-codec"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}