gofiber/fiber · error

fiber: shared state %s %s is not configured

Error message

fiber: shared state %s %s is not configured

What it means

Returned by sharedStateCodecNotConfiguredError (shared_state.go:405) when a shared-state codec operation is attempted for a format whose encoder/decoder was never configured. Fiber ships defaults only for JSON and XML; MsgPack and CBOR require explicit cfg.MsgPackEncoder/Decoder, cfg.CBOREncoder/Decoder. The message names both the format and the direction (encoder/decoder).

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 9a4c7e57fe)

Solutions

  1. Provide both encoder and decoder for the format in fiber.Config: MsgPackEncoder/MsgPackDecoder (or CBOR variants).
  2. Use a supported codec implementation, e.g. github.com/vmihailenco/msgpack/v5 or github.com/fxamacker/cbor.
  3. If you only need JSON/XML, switch to SetJSON/SetXML which have working defaults.
  4. Register codecs once at app construction; do not rely on per-call configuration.

Example fix

// before: using msgpack without codecs
app := fiber.New(fiber.Config{SharedStorage: store})
_ = app.SharedState().SetMsgPack(ctx, "k", v, ttl)

// after: wire msgpack codecs in Config
import "github.com/vmihailenco/msgpack/v5"
app := fiber.New(fiber.Config{
    SharedStorage:   store,
    MsgPackEncoder:  msgpack.Marshal,
    MsgPackDecoder:  msgpack.Unmarshal,
})
Defensive patterns

Strategy: validation

Validate before calling

if cfg.MsgPackEncoder == nil || cfg.MsgPackDecoder == nil {
    // either wire codecs or do not use SetMsgPack/GetMsgPack
    cfg.MsgPackEncoder = msgpack.Marshal
    cfg.MsgPackDecoder = msgpack.Unmarshal
}

Prevention

When it happens

Trigger: Calling app.SharedState().SetMsgPack/GetMsgPack without setting Config.MsgPackEncoder and Config.MsgPackDecoder; calling SetCBOR/GetCBOR without Config.CBOREncoder/Decoder. encodeSharedStateValue/decodeSharedStateValue see a nil codec function and return this error.

Common situations: Using SharedState MsgPack/CBOR APIs for the first time without wiring codecs; removing the codec config during a refactor; assuming defaults exist for all formats like JSON.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/6436dfd17e1d5562.json. Report an issue: GitHub.