Skip to content

Expose bufio.Scanner errors and buffer size from Scanner - #174

Open
shogo82148 wants to merge 1 commit into
masterfrom
scanner-err-buffer
Open

shogo82148 wants to merge 1 commit into
masterfrom
scanner-err-buffer

Conversation

@shogo82148

Copy link
Copy Markdown
Contributor

Problem

Scanner silently stopped when the underlying bufio.Scanner failed. For example, a line longer than bufio.MaxScanTokenSize (64 KiB) made Scan return false, and the caller lost every entry after that line without any notice. There was also no way to raise the limit.

reviewdog worked around this in reviewdog/reviewdog#3003 by truncating long lines before passing them to the scanner. That workaround silently cuts long messages, and formats whose position info sits at the end of the line no longer match.

Changes

  • Add Scanner.Err(), which returns the underlying bufio.Scanner error (such as bufio.ErrTooLong).
  • Add Scanner.Buffer(buf []byte, max int), which works like bufio.Scanner.Buffer. It lets callers raise the maximum line length and panics if called after scanning has started.
  • Document in Scan that it also returns false on error.
  • Make the errorformat command return Scanner.Err().

The existing API is unchanged; these are additions only.

Tests

  • A line over 64 KiB stops scanning, keeps the entries before it, and makes Err() return bufio.ErrTooLong.
  • With Buffer(nil, 1 MiB), the long line and the lines after it are parsed correctly.
  • Buffer panics after Scan.
  • TestScanner_Scan now also checks that Err() is nil.

🤖 Generated with Claude Code

Scanner silently stopped when the underlying bufio.Scanner failed, e.g.
on a line longer than bufio.MaxScanTokenSize (64 KiB), so callers lost
every entry after that line without any notice.

- Add Scanner.Err, which returns the underlying bufio.Scanner error
  (such as bufio.ErrTooLong).
- Add Scanner.Buffer, which works like bufio.Scanner.Buffer and lets
  callers raise the maximum line length. It panics if called after
  scanning has started.
- Make the errorformat command return Scanner.Err.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant