{"record":{"id":"328b139089a2047a","repo":"glanceapp/glance","slug":"marshaling-body-v","errorCode":null,"errorMessage":"marshaling body: %v","messagePattern":"marshaling body: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/widget-custom-api.go","lineNumber":156,"sourceCode":"\n\tif req.Body != nil {\n\t\tif req.Method == \"\" {\n\t\t\treq.Method = http.MethodPost\n\t\t}\n\n\t\tif req.BodyType == \"\" {\n\t\t\treq.BodyType = \"json\"\n\t\t}\n\n\t\tif req.BodyType != \"json\" && req.BodyType != \"string\" {\n\t\t\treturn errors.New(\"invalid body type, must be either 'json' or 'string'\")\n\t\t}\n\n\t\tswitch req.BodyType {\n\t\tcase \"json\":\n\t\t\tencoded, err := json.Marshal(req.Body)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"marshaling body: %v\", err)\n\t\t\t}\n\n\t\t\treq.bodyReader = bytes.NewReader(encoded)\n\t\tcase \"string\":\n\t\t\tbodyAsString, ok := req.Body.(string)\n\t\t\tif !ok {\n\t\t\t\treturn errors.New(\"body must be a string when body-type is 'string'\")\n\t\t\t}\n\n\t\t\treq.bodyReader = strings.NewReader(bodyAsString)\n\t\t}\n\n\t} else if req.Method == \"\" {\n\t\treq.Method = http.MethodGet\n\t}\n\n\thttpReq, err := http.NewRequest(strings.ToUpper(req.Method), req.URL, req.bodyReader)\n\tif err != nil {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/widget-custom-api.go#L138-L174","documentation":"Returned from CustomAPIRequest.initialize when body-type is json and json.Marshal(req.Body) fails. req.Body comes straight from YAML decoding, so this means the configured body contains a value Go's encoding/json cannot serialize.","triggerScenarios":"Body value decodes to a type json.Marshal rejects: NaN/Infinity floats (e.g. from YAML .nan/.inf), cyclic structures, channels/funcs, or a map with non-stringable complex keys depending on the YAML decoder's output types.","commonSituations":"YAML body containing .nan or .inf; exotic YAML anchors producing recursive structures; expecting a plain string body while body-type: json is set.","solutions":["If the body is a plain string, switch body-type: string so it is sent verbatim.","Remove .nan/.inf or unserializable values from the YAML body block.","Keep the JSON body to plain mappings, sequences, strings, numbers, booleans.","Check YAML anchors/merge keys (<<) are not producing unexpected nested structures."],"exampleFix":"# before\nbody-type: json\nbody: \"plain string body\"\n\n# after\nbody-type: string\nbody: \"plain string body\"","handlingStrategy":"validation","validationCode":"if widget.BodyType == \"json\" && widget.Body != nil {\n    if _, err := json.Marshal(widget.Body); err != nil {\n        return fmt.Errorf(\"body is not JSON-serializable: %w\", err)\n    }\n}","typeGuard":"// string bodies only make sense with body-type: string\nif s, ok := req.Body.(string); ok && req.BodyType == \"\" {\n    req.BodyType = \"string\" // let plain strings default to string, not json\n    _ = s\n}","tryCatchPattern":null,"preventionTips":["Match body-type to the body's actual shape: mapping/list → json, scalar text → string.","Avoid .nan/.inf and exotic YAML constructs in request bodies.","Test the request with curl -d @body.json before putting it in config."],"tags":["json","config","custom-api","widget"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}