{"record":{"id":"1a98834044f9950a","repo":"gohugoio/hugo","slug":"error-parsing-json-line-n-1a9883","errorCode":null,"errorMessage":"Error parsing JSON line\\n","messagePattern":"Error parsing JSON line\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/genwebp/webp.c","lineNumber":333,"sourceCode":"        {\n            return 1;\n        }\n    }\n\n    config->use_sharp_yuv = opts.useSharpYuv ? 1 : 0;\n    config->method = opts.method;\n\n    return 1;\n}\n\nInputMessage parse_input_message(const char *line)\n{\n    InputMessage msg = {0};\n\n    JSON_Value *root_value = json_parse_string(line);\n    if (root_value == NULL)\n    {\n        fprintf(stderr, \"Error parsing JSON line\\n\");\n        return msg;\n    }\n\n    if (json_value_get_type(root_value) != JSONObject)\n    {\n        fprintf(stderr, \"Error: Line did not parse to a valid JSON object\\n\");\n        json_value_free(root_value);\n        return msg;\n    }\n\n    JSON_Object *root_object = json_value_get_object(root_value);\n\n    JSON_Object *header_object = json_object_get_object(root_object, \"header\");\n    if (header_object != NULL)\n    {\n        msg.header.version = (int)json_object_get_number(header_object, \"version\");\n        msg.header.id = (int)json_object_get_number(header_object, \"id\");\n        const char *command_str = json_object_get_string(header_object, \"command\");","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/genwebp/webp.c#L315-L351","documentation":"Printed by genwebp's parse_input_message (webp.c:333) when json_parse_string returns NULL for a stdin line. Identical semantics to the genavif counterpart (820): the line was not valid JSON, parson built no value tree, the function returns an empty InputMessage, and no response is written. The genwebp worker reads one JSON command line per iteration followed by a 16-byte blob header and blob payload.","triggerScenarios":"A non-JSON byte sequence on genwebp's stdin: a prior blob-size mismatch causing binary bytes to be read as a command line, a line longer than MAX_LINE_LENGTH (4096) split by fgets, a debug writer accidentally attached to the RPC pipe, or a hand-crafted test sending plain text.","commonSituations":"Stream desynchronization after a previous short/long blob read, mismatched genwebp binary speaking a different envelope than the host, broken pipe / killed host mid-send, or test fixtures missing the trailing newline.","solutions":["Correlate with the previous stderr lines: this is usually downstream of an earlier framing error.","Verify the host writes one JSON object terminated by '\\n' followed by exactly 16 header bytes plus the declared payload.","Keep command JSON under 4096 bytes; large frameDurations arrays can exceed MAX_LINE_LENGTH.","Capture fd 0 bytes with strace to see the exact malformed line.","Ensure no other writer touches genwebp's stdin."],"exampleFix":"// before (host): no newline, two commands concatenated\nw.Write([]byte(`{\"header\":{\"command\":\"config\"}}`))\nw.Write([]byte(`{\"header\":{\"command\":\"decode\"}}`))\n\n// after: newline-terminated, one per write\nw.Write([]byte(\"{\\\"header\\\":{\\\"command\\\":\\\"config\\\"}}\\n\"))\n// then send blob; then next command","handlingStrategy":"validation","validationCode":"func writeWebpCommand(w io.Writer, cmd map[string]any) error {\n    b, err := json.Marshal(cmd)\n    if err != nil { return err }\n    if len(b) > 4096 { return fmt.Errorf(\"command JSON %d bytes exceeds 4096\", len(b)) }\n    line := append(b, '\\n')\n    n, err := w.Write(line)\n    if err != nil || n != len(line) { return errShortWrite }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Terminate each command with '\\n' and keep under 4096 bytes.","Never share genwebp's stdin with another writer.","Respawn the worker after any blob-read error rather than reusing the stream.","Capture fd 0 with strace when debugging to see the exact malformed line."],"tags":["rpc","json","protocol","webp","stdin"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}