{"record":{"id":"19b9d34a69556e91","repo":"charmbracelet/crush","slug":"parse-error-w","errorCode":null,"errorMessage":"parse error: %w","messagePattern":"parse error: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/shell/jq.go","lineNumber":282,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\t// Decode potentially multiple JSON values from the stream.\n\t\tdec := json.NewDecoder(strings.NewReader(string(data)))\n\t\tvar streamVals []any\n\t\tfor {\n\t\t\tif err := ctx.Err(); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tvar v any\n\t\t\tif err := dec.Decode(&v); err != nil {\n\t\t\t\tif err == io.EOF {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"parse error: %w\", err)\n\t\t\t}\n\t\t\tstreamVals = append(streamVals, v)\n\t\t}\n\n\t\tif slurp {\n\t\t\tvals = append(vals, streamVals)\n\t\t} else {\n\t\t\tvals = append(vals, streamVals...)\n\t\t}\n\t}\n\n\tif len(vals) == 0 {\n\t\treturn []any{nil}, nil\n\t}\n\treturn vals, nil\n}\n\n// ctxReader wraps an io.Reader so that each Read call checks ctx first.","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/shell/jq.go#L264-L300","documentation":"readInputs in the jq builtin wraps a JSON decoding failure. When reading jq inputs without -R (raw input), the stream is decoded as one or more JSON values via json.Decoder; any decode error other than io.EOF (trailing garbage, invalid JSON) is returned wrapped as \"parse error: <detail>\".","triggerScenarios":"handleJQ receives input (file or stdin) in JSON mode; dec.Decode hits malformed JSON such as `{foo}`, truncated documents, concatenated values with stray separators, or invalid UTF-8, while the context is still live.","commonSituations":"Piping output of a command that emits logs mixed with JSON; feeding empty files with stray whitespace or BOM; passing HTML error pages instead of JSON; forgetting -R when inputs are raw text lines.","solutions":["Validate the input is well-formed JSON (e.g. `jq . input.json`) and fix the producer or the data.","If inputs are raw text, not JSON, add the raw-input flag to the jq invocation.","Strip non-JSON noise (log lines, BOM) before piping into the jq tool.","Check the wrapped json error's offset message to locate the exact malformed byte."],"exampleFix":"// before\ncat app.log | crush jq '.msg'\n// after\ncat app.log | grep '^{' | crush jq '.msg'","handlingStrategy":"validation","validationCode":"var probe any\nif err := json.Unmarshal(trimmedInput, &probe); err != nil {\n    // not valid JSON — fix the producer or switch to raw-input mode\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.HasPrefix(err.Error(), \"parse error: \") {\n        // JSON decode failure in jq input; use wrapped offset to locate it\n    }\n}","preventionTips":["Ensure upstream commands emit pure JSON (no log lines interleaved).","Use raw-input mode for non-JSON text inputs.","Strip BOM/whitespace before piping JSON.","Validate generated JSON with a linter in CI."],"tags":["jq","json","parse-error","stdin"],"backgroundTag":"invalid-json-input","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}