Repository navigation
Expose bufio.Scanner errors and buffer size from Scanner - #174
Open
shogo82148 wants to merge 1 commit into
Open
shogo82148 wants to merge 1 commit into
shogo82148 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Scannersilently stopped when the underlyingbufio.Scannerfailed. For example, a line longer thanbufio.MaxScanTokenSize(64 KiB) madeScanreturn 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
Scanner.Err(), which returns the underlyingbufio.Scannererror (such asbufio.ErrTooLong).Scanner.Buffer(buf []byte, max int), which works likebufio.Scanner.Buffer. It lets callers raise the maximum line length and panics if called after scanning has started.Scanthat it also returns false on error.errorformatcommand returnScanner.Err().The existing API is unchanged; these are additions only.
Tests
Err()returnbufio.ErrTooLong.Buffer(nil, 1 MiB), the long line and the lines after it are parsed correctly.Bufferpanics afterScan.TestScanner_Scannow also checks thatErr()is nil.🤖 Generated with Claude Code