gohugoio/hugo · error · Error
Error parsing JSON '${new TextDecoder().decode(arr)}' from s
Error message
Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message} What it means
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.
Source
Thrown at internal/warpc/js/common.js:57
currentLine = [...currentLine, ...buffer.subarray(0, bytesRead)];
// Check for newline. If not, we need to read more data.
if (!currentLine.includes(10)) {
continue;
}
// Split array into chunks by newline.
let i = 0;
for (let j = 0; i < currentLine.length; i++) {
if (currentLine[i] === 10) {
const chunk = currentLine.splice(j, i + 1);
const arr = new Uint8Array(chunk);
let message;
try {
message = JSON.parse(new TextDecoder().decode(arr));
} catch (e) {
throw new Error(`Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message}`);
}
try {
handle(message);
} catch (e) {
let header = message.header;
header.err = e.message;
writeOutput({ header: header });
}
j = i + 1;
}
}
// Remove processed data.
currentLine = currentLine.slice(i);
}
}
View on GitHub (pinned to 52c9bd7908)
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
Defensive patterns
Strategy: try-catch
Validate before calling
function isValidJsonl(line) { try { JSON.parse(line); return true; } catch { return false; } }
// producer: assert isValidJsonl(line) before writing to the pipe Try / catch
try { message = JSON.parse(text); } catch (e) { logBadLine(text, e); continue; } Prevention
- Test producer output with a JSONL validator before piping to warpc
- Never interleave log lines with the JSONL stream
When it happens
Trigger: A line in the JSONL stream that is not valid JSON (truncated, non-JSON, mixed encoding, or split incorrectly) reaches JSON.parse.
Common situations: 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.
Related errors
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/3172e3f554a64fe5.
Report an issue: GitHub.