{"record":{"id":"3172e3f554a64fe5","repo":"gohugoio/hugo","slug":"error-parsing-json-new-textdecoder-decode-arr","errorCode":null,"errorMessage":"Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message}","messagePattern":"Error parsing JSON '(.+?)' from stdin: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/warpc/js/common.js","lineNumber":57,"sourceCode":"\n\t\tcurrentLine = [...currentLine, ...buffer.subarray(0, bytesRead)];\n\n\t\t// Check for newline. If not, we need to read more data.\n\t\tif (!currentLine.includes(10)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Split array into chunks by newline.\n\t\tlet i = 0;\n\t\tfor (let j = 0; i < currentLine.length; i++) {\n\t\t\tif (currentLine[i] === 10) {\n\t\t\t\tconst chunk = currentLine.splice(j, i + 1);\n\t\t\t\tconst arr = new Uint8Array(chunk);\n\t\t\t\tlet message;\n\t\t\t\ttry {\n\t\t\t\t\tmessage = JSON.parse(new TextDecoder().decode(arr));\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new Error(`Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message}`);\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\thandle(message);\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlet header = message.header;\n\t\t\t\t\theader.err = e.message;\n\t\t\t\t\twriteOutput({ header: header });\n\t\t\t\t}\n\n\t\t\t\tj = i + 1;\n\t\t\t}\n\t\t}\n\t\t// Remove processed data.\n\t\tcurrentLine = currentLine.slice(i);\n\t}\n}\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/js/common.js#L39-L75","documentation":"Each newline-delimited chunk read from stdin is decoded and passed to JSON.parse (common.js:55). If the chunk is not valid JSON, the parse error is rethrown with the offending text included so the malformed line is visible in the error message.","triggerScenarios":"A line in the JSONL stream that is not valid JSON (truncated, non-JSON, mixed encoding, or split incorrectly) reaches JSON.parse.","commonSituations":"The producer writes non-JSONL or partial JSON; a BOM/encoding mismatch; an incomplete chunk because newlines were absent; debug logging interleaved into the stream.","solutions":["Validate the producer emits strict JSONL: one JSON object per line, UTF-8, no BOM","Capture the offending line printed in the error and fix the producer","Ensure 0x0A newlines separate each message as the splitter expects"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function isValidJsonl(line) { try { JSON.parse(line); return true; } catch { return false; } }\n// producer: assert isValidJsonl(line) before writing to the pipe","typeGuard":null,"tryCatchPattern":"try { message = JSON.parse(text); } catch (e) { logBadLine(text, e); continue; }","preventionTips":["Test producer output with a JSONL validator before piping to warpc","Never interleave log lines with the JSONL stream"],"tags":["warpc","wasm","json","jsonl","javascript"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}