{"record":{"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":"exception","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/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/idempotency/idempotency.go#L157-L188","documentation":"Returned when res.MarshalMsg(nil) fails while serializing the cached response to msgpack before storage. The response struct (status, body, headers) is msgpack-generated; marshal failures are rare and indicate a header map/value that the generated marshaler cannot encode (e.g. a non-byte-slice body or unsupported map key type introduced by a custom Bind).","triggerScenarios":"Constructing the response to cache and calling the msgpack-generated MarshalMsg on it returns a non-nil error — typically an unencodable value in the Headers map (non-string key, nil slice element) or a body that is not []byte after a refactor.","commonSituations":"A schema/codegen drift after regenerating manager_msgp.go, an upstream change that puts an unexpected type into response.Headers, or running against a msgpack version with stricter encoding rules.","solutions":["Regenerate msgpack code: `make generate` (or go generate ./middleware/idempotency/...).","Ensure response.Body stays []byte and response.Headers stays map[string][]string.","Run the idempotency unit tests to confirm the schema round-trips.","Inspect the wrapped %w for the precise encode error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `make generate` after touching the response struct.","Keep response.Body as []byte and response.Headers as map[string][]string.","Add a round-trip unit test for the cached response schema."],"tags":["idempotency","msgpack","serialization","codegen"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}