{"record":{"id":"61fc2053ba3bc7a6","repo":"SigNoz/signoz","slug":"couldn-t-serialize-request-payload-to-json-w","errorCode":null,"errorMessage":"couldn't serialize request payload to JSON: %w","messagePattern":"couldn't serialize request payload to JSON: %w","errorType":"http","errorClass":"basemodel.ApiError","httpStatus":500,"severity":"error","filePath":"ee/query-service/app/api/cloudIntegrations.go","lineNumber":315,"sourceCode":"\t\t\"X-Consumer-Username\":    \"lid:00000000-0000-0000-0000-000000000000\",\n\t\t\"X-Consumer-Groups\":      \"ns:default\",\n\t}\n\n\treturn requestAndParseResponse[ResponseType](ctx, reqUrl, headers, payload)\n}\n\nfunc requestAndParseResponse[ResponseType any](\n\tctx context.Context, url string, headers map[string]string, payload any,\n) (*ResponseType, *basemodel.ApiError) {\n\n\treqMethod := http.MethodGet\n\tvar reqBody io.Reader\n\tif payload != nil {\n\t\treqMethod = http.MethodPost\n\n\t\tbodyJson, err := json.Marshal(payload)\n\t\tif err != nil {\n\t\t\treturn nil, basemodel.InternalError(fmt.Errorf(\n\t\t\t\t\"couldn't serialize request payload to JSON: %w\", err,\n\t\t\t))\n\t\t}\n\t\treqBody = bytes.NewBuffer([]byte(bodyJson))\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, reqMethod, url, reqBody)\n\tif err != nil {\n\t\treturn nil, basemodel.InternalError(fmt.Errorf(\n\t\t\t\"couldn't prepare request: %w\", err,\n\t\t))\n\t}\n\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tclient := &http.Client{","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/ee/query-service/app/api/cloudIntegrations.go#L297-L333","documentation":"json.Marshal of the request payload failed inside the generic gateway request helper (requestAndParseResponse). The payload contains a type that cannot be serialized to JSON, such as a channel, func, or a value with an unmarshalable field.","triggerScenarios":"Calling requestGateway/requestAndParseResponse with a payload struct containing unsupported types (chan, func, complex, cyclic pointer) or a MarshalJSON method that errors.","commonSituations":"Adding a new field of an unserializable type to a gateway request struct, or a custom MarshalJSON that returns an error.","solutions":["Inspect the payload struct for channels, funcs, or cyclic references","Fix or remove the offending field / custom MarshalJSON","Unit-test marshalling the payload before passing it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(payload); err != nil {\n    return fmt.Errorf(\"payload not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"Pre-marshal payloads (see validationCode) so unserializable types fail with a clear caller-side error before the HTTP path.","preventionTips":["Never put chans/funcs in request structs","Unit-test JSON round-trips for every request DTO"],"tags":["json","serialization","gateway","http-client"],"backgroundTag":"json-marshal-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}