{"record":{"id":"d45105ec58e9623c","repo":"hashicorp/nomad","slug":"failed-to-decode-log-endpoint-response-as-json-q","errorCode":null,"errorMessage":"failed to decode log endpoint response as JSON: %q","messagePattern":"failed to decode log endpoint response as JSON: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/fs.go","lineNumber":307,"sourceCode":"\t\t\t// Check if we have been cancelled\n\t\t\tselect {\n\t\t\tcase <-cancel:\n\t\t\t\tclose(frames)\n\t\t\t\treturn\n\t\t\tdefault:\n\t\t\t}\n\n\t\t\t// Decode the next frame\n\t\t\tvar frame StreamFrame\n\t\t\tif err := dec.Decode(&frame); err != nil {\n\t\t\t\tif err == io.EOF || err == io.ErrClosedPipe {\n\t\t\t\t\tclose(frames)\n\t\t\t\t} else {\n\t\t\t\t\tbuf, err2 := io.ReadAll(dec.Buffered())\n\t\t\t\t\tif err2 != nil {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"failed to decode and failed to read buffered data: %w\", errors.Join(err, err2))\n\t\t\t\t\t} else {\n\t\t\t\t\t\terrCh <- fmt.Errorf(\"failed to decode log endpoint response as JSON: %q\", buf)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Discard heartbeat frames\n\t\t\tif frame.IsHeartbeat() {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tframes <- &frame\n\t\t}\n\t}()\n\n\treturn frames, errCh\n}\n\n// FrameReader is used to convert a stream of frames into a read closer.","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/api/fs.go#L289-L325","documentation":"While streaming logs, a JSON decode error occurred but the buffered leftover data WAS readable — the client reports the raw buffered bytes with this message so you can see exactly what non-JSON payload broke the stream. It is the diagnostic counterpart to the 'failed to decode and failed to read buffered data' error.","triggerScenarios":"The log/FS stream endpoint returns non-JSON content (plain text error, HTML error page, empty/garbage body) where decode fails but io.ReadAll(dec.Buffered()) succeeds.","commonSituations":"Nomad agent returning 5xx body mid-stream; hitting the wrong port; auth proxy returning an HTML login page; allocator crashed and stream closed with junk tail.","solutions":["Read the %q payload in the error to identify what the server actually sent","Check the allocation/client node health (nomad alloc status)","Confirm the request goes to a Nomad agent HTTP endpoint, not a proxy or UI","Retry the stream after the transient condition clears"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := streamLogs(ctx, allocID); err != nil {\n    var payloadErr *nomadStreamError\n    if errors.As(err, &payloadErr) {\n        log.Printf(\"non-JSON payload received: %q\", payloadErr.buf)\n    }\n    return fallbackToDirectFetch(ctx, allocID)\n}","preventionTips":["Inspect the quoted buffered payload in the error to diagnose the real server response","Bypass intermediaries when streaming logs","Confirm client-node connectivity before streaming"],"tags":["streaming","json","nomad-api"],"backgroundTag":"json-decode-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}