{"record":{"id":"e3f0f0b14ce5811b","repo":"gofiber/fiber","slug":"limiter-failed-to-marshal-key-q-w","errorCode":null,"errorMessage":"limiter: failed to marshal key %q: %w","messagePattern":"limiter: failed to marshal key %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/limiter/manager.go","lineNumber":102,"sourceCode":"\tif value == nil {\n\t\treturn m.acquire(), nil\n\t}\n\n\tit, ok := value.(*item)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"limiter: unexpected entry type %T for key %q\", value, m.logKey(key))\n\t}\n\n\treturn it, nil\n}\n\n// set data to storage or memory\nfunc (m *manager) set(ctx context.Context, key string, it *item, exp time.Duration) error {\n\tif m.storage != nil {\n\t\traw, err := it.MarshalMsg(nil)\n\t\tif err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"limiter: failed to marshal key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tif err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {\n\t\t\tm.release(it)\n\t\t\treturn fmt.Errorf(\"limiter: failed to store key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\tm.release(it)\n\t\treturn nil\n\t}\n\n\tm.memory.Set(key, it, exp)\n\treturn nil\n}\n\nfunc (m *manager) logKey(key string) string {\n\tif m.shouldRedactKeys {\n\t\treturn redactedKey\n\t}\n\treturn key","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/limiter/manager.go#L84-L120","documentation":"Before writing an item to external storage, the manager calls it.MarshalMsg(nil) (msgp-generated). For this simple struct (three numeric fields), MarshalMsg is essentially incapable of failing under normal conditions; an error indicates a corrupted generated code path, nil receiver, or an internal msgp invariant violation.","triggerScenarios":"Effectively unreachable in production. Theoretical triggers: msgp-generated code out of sync with the struct (go generate not re-run after a field change), memory pressure causing an allocation failure inside the encoder, or a manually edited manager_msgp.go.","commonSituations":"Developer hand-edited manager_msgp.go; msgp version skew between the version that generated the file and the version imported at build time; corrupt build cache.","solutions":["Regenerate the msgp code: go run github.com/tinylib/msgp -o=manager_msgp.go -tests=false -unexported in middleware/limiter.","Run go mod tidy to align the msgp runtime library version with the generator version.","Clear the Go build cache: go clean -cache and rebuild.","Confirm the item struct in manager.go matches the msgp tag expectations (no missing/renamed fields)."],"exampleFix":"// before: stale generated code\n// manager_msgp.go out of sync with item struct\n\n// after: regenerate\n// run: go generate ./middleware/limiter/...","handlingStrategy":"validation","validationCode":"// CI step: regenerate and diff msgp output to catch drift.\n// go generate ./middleware/limiter/... && git diff --exit-code manager_msgp.go","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run go generate as part of the build/CI pipeline.","Pin the msgp version in go.mod and go.sum so generator and runtime match.","Never hand-edit generated *_msgp.go files."],"tags":["limiter","msgpack","codegen","internal"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}