gofiber/fiber · error
fiber: shared state is not configured
Error message
fiber: shared state %s %s is not configured
What it means
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.
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.
Example fix
// before — using msgpack without configuring the codec
app := fiber.New(fiber.Config{
SharedStorage: storage,
// MsgPackEncoder/Decoder missing
})
app.State().Shared().SetMsgPack("k", v, 0)
// -> fiber: shared state msgpack encoder is not configured
// after — wire the codec
app := fiber.New(fiber.Config{
SharedStorage: storage,
MsgPackEncoder: msgpack.Marshal,
MsgPackDecoder: msgpack.Unmarshal,
})
app.State().Shared().SetMsgPack("k", v, 0) Defensive patterns
Strategy: validation
Validate before calling
// Assert at startup that the codecs you use are configured.
func requireCodecs(app *fiber.App, useMsgPack, useCBOR bool) error {
cfg := app.Config()
if useMsgPack && (cfg.MsgPackEncoder == nil || cfg.MsgPackDecoder == nil) {
return errors.New("msgpack codec required but not configured")
}
if useCBOR && (cfg.CBOREncoder == nil || cfg.CBORDecoder == nil) {
return errors.New("cbor codec required but not configured")
}
return nil
} Try / catch
if err := app.State().Shared().SetMsgPack(k, v, ttl); err != nil {
if strings.Contains(err.Error(), "is not configured") {
log.Fatal("configure MsgPackEncoder/Decoder before using MsgPack shared state")
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- fiber: failed to decode shared state
- fiber: failed to encode shared state
- binder: msgpack is not configured, please check docs…
- binder: must explicitly set up CBOR, please check docs…
- ErrSharedStorageNotConfigured
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/6436dfd17e1d5562.
Report an issue: GitHub.
Appendix: source
Thrown at shared_state.go:405
defer func() {
recovered = recover()
}()
err = decoder(data, out)
}()
if recovered != nil {
return sharedStateCodecPanicError("decode", format, recovered)
}
if err != nil {
return fmt.Errorf("fiber: failed to decode shared state %s value: %w", format, err)
}
return nil
}
func sharedStateCodecNotConfiguredError(format, direction string) error {
return fmt.Errorf("fiber: shared state %s %s is not configured", format, direction)
}
func sharedStateCodecPanicError(operation, format string, recovered any) error {
if err, ok := recovered.(error); ok {
return fmt.Errorf("fiber: failed to %s shared state %s value: %w", operation, format, err)
}
return fmt.Errorf("fiber: failed to %s shared state %s value: %v", operation, format, recovered)
}
func (s *SharedState) storageKey(key string) (string, bool) {
if key == "" {
return "", false
}
return s.prefix + hex.EncodeToString(utils.UnsafeBytes(key)), true
}
View on GitHub (pinned to a105acad6c)