{"record":{"id":"6bb860cabb1f1ab2","repo":"tomnomnom/gron","slug":"error-reading-multiline-input-s-s","errorCode":null,"errorMessage":"error reading multiline input: %s: %s","messagePattern":"error reading multiline input: (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":328,"sourceCode":"\n\t\tfor _, s := range ss {\n\t\t\tif opts&optJSON > 0 {\n\t\t\t\ts, err = s.jsonify()\n\t\t\t\tif err != nil {\n\t\t\t\t\tgoto out\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tfmt.Fprintln(w, conv(s))\n\t\t}\n\t}\n\tif err = sc.Err(); err != nil {\n\t\terrstr = \"error reading multiline input: %s\"\n\t}\n\nout:\n\tif err != nil {\n\t\treturn exitFormStatements, fmt.Errorf(errstr+\": %s\", err)\n\t}\n\treturn exitOK, nil\n\n}\n\n// ungron is the reverse of gron. Given assignment statements as input,\n// it returns JSON. The only option is optMonochrome\nfunc ungron(r io.Reader, w io.Writer, opts int) (int, error) {\n\tscanner := bufio.NewScanner(r)\n\tvar maker statementmaker\n\n\t// Allow larger internal buffer of the scanner (min: 64KiB ~ max: 1MiB)\n\tscanner.Buffer(make([]byte, 64*1024), 1024*1024)\n\n\tif opts&optJSON > 0 {\n\t\tmaker = statementFromJSONSpec\n\t} else {\n\t\tmaker = statementFromStringMaker","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/tomnomnom/gron/blob/88a6234ea2d0c487090988182ad9a7cdf6def924/main.go#L310-L346","documentation":"gronStream reads one JSON object per line. If the underlying bufio.Scanner reports an I/O error while reading (sc.Err() != nil), the failure is wrapped as \"error reading multiline input: %s: %s\" with exit code exitFormStatements. The second %s carries the scanner error (e.g. token too long, read failure).","triggerScenarios":"Reading `gron --stream` input from a broken pipe, a file that disappears mid-read, a failing pipe/fifo, or input lines exceeding the scanner's 1MiB buffer (bufio.ErrTooLong).","commonSituations":"Streaming from a tail -f or socket that errors mid-stream; huge single-line JSON documents over 1MB in a line-oriented stream; disk/network I/O faults while reading stdin.","solutions":["Split or compact overly long lines so each is under the 1MiB scanner limit","Check that the input source (file, pipe, socket) is healthy and not closing mid-read","Retry the streaming read if the upstream producer was interrupted","Fall back to plain `gron` (single document mode) if the data is one large JSON document rather than NDJSON"],"exampleFix":"// before\n$ gron -s < huge_line.json   // bufio.Scanner: token too long\n\n// after\n$ jq -c . huge.json | split -l 1 --filter='gron' // or increase/max-lines under 1MiB per line","handlingStrategy":"fallback","validationCode":"// pre-check line sizes before streaming\nsc := bufio.NewScanner(r)\nfor sc.Scan() {\n\tif len(sc.Bytes()) > 1024*1024 { /* split or reject line */ }\n}","typeGuard":null,"tryCatchPattern":"code, err := gronStream(input, output, opts)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"error reading multiline input:\") {\n\t\t// retry stream or fall back to single-document gron\n\t}\n\treturn err\n}","preventionTips":["Keep NDJSON lines under 1MiB","Ensure stream producers outlive the gron process","Retry transient I/O failures on pipes/sockets"],"tags":["go","gron","io","streaming"],"backgroundTag":"file-read-failed","analyzedSha":"88a6234ea2d0c487090988182ad9a7cdf6def924","analyzedAt":"2026-09-06T11:35:31.658Z","contentChangedAt":"2026-09-06T11:35:31.658Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}