{"id":"7521004e871cc21a","repo":"gofiber/fiber","slug":"failed-to-marshal-response-w","errorCode":null,"errorMessage":"failed to marshal response: %w","messagePattern":"failed to marshal response: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"middleware/idempotency/idempotency.go","lineNumber":175,"sourceCode":"\n\t\t\tif keepResponseHeaders == nil {\n\t\t\t\t// Keep all\n\t\t\t\tres.Headers = headers\n\t\t\t} else {\n\t\t\t\t// Filter\n\t\t\t\tres.Headers = make(map[string][]string)\n\t\t\t\tfor h, vals := range headers {\n\t\t\t\t\tif shouldKeepHeader(h) {\n\t\t\t\t\t\tres.Headers[h] = vals\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Marshal response\n\t\tbs, err := res.MarshalMsg(nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to marshal response: %w\", err)\n\t\t}\n\n\t\t// Store response\n\t\tif err := cfg.Storage.SetWithContext(c, key, bs, cfg.Lifetime); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to save response: %w\", err)\n\t\t}\n\n\t\t_ = c.Locals(localsKeyWasPutToCache, true)\n\n\t\treturn nil\n\t}\n}\n","sourceCodeStart":157,"sourceCodeEnd":188,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/idempotency/idempotency.go#L157-L188","documentation":"Returned by the middleware (idempotency.go:174-176) when res.MarshalMsg(nil) fails for the response struct. msgpack marshaling of a fixed struct of (int, []byte, map[string][]string) does not fail under normal conditions.","triggerScenarios":"Unreachable for the current response struct shape. Would require an embedded type that implements MarshalMsg incorrectly, or a msgp codegen mismatch (regenerated msgp.go out of sync with the struct).","commonSituations":"Editing the response struct without re-running `go generate` (msgp), leaving the MarshalMsg method out of sync with the field set; very rare.","solutions":["Run `make generate` (msgp codegen) after any change to the response struct.","Verify manager_msgp.go / response_msgp.go are present and not hand-edited.","Treat occurrence as a build/codegen bug."],"exampleFix":"# before — edited response struct, forgot regen\n$ go build ./...\n\n# after\n$ make generate\n$ go build ./...","handlingStrategy":"validation","validationCode":"// CI step: regenerate msgp codegen and fail if diff\n// make generate && git diff --exit-code middleware/idempotency/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `make generate` whenever the response struct changes.","Add a CI check that msgp-generated files are committed and current.","Never hand-edit msgp-generated files."],"tags":["idempotency","msgpack","codegen","unreachable"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}