Repository navigation
feat: add Scanner.WithScannerBufferSize for games over the token limit - #133
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #133 +/- ##
==========================================
- Coverage 81.14% 81.12% -0.02%
==========================================
Files 28 28
Lines 4470 4477 +7
==========================================
+ Hits 3627 3632 +5
Misses 716 716
- Partials 127 129 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bufio.Scanner rejects a token larger than 64 KiB, so the scanner could not read a game carrying large comments or variations — the longest possible chess game (17697 moves) fails with "bufio.Scanner: token too long". WithScannerBufferSize raises the limit for callers that need it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CorentinGS
force-pushed
the
fix/v2-scanner-buffer-size
branch
from
October 25, 2026 09:56
facec9d to
045bccc
Compare
The option now clamps the size to bufio's default instead of the scanner checking it later, and NewScanner always sets the buffer, so no new branch is introduced. 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
bufio.Scannerrejects any token larger than 64 KiB, and the scanner's split function returns one whole game per token. A game carrying large comments or variations therefore cannot be read at all:This is exactly the case reported in #129: the longest possible chess game (17697 moves, 131 KB) fails with
bufio.Scanner: token too long.Fix
WithScannerBufferSizeraises the scanner's maximum token size, mirroringWithPGNBufferSizeon the v3 branch:The default is unchanged (64 KiB), so this is opt-in and does not change behaviour for existing callers.
With the option, the longest possible chess game parses:
Tests
TestScannerBufferSizeAllowsLargeGames(new): a game over the default limit is rejected by the default scanner and read successfully withWithScannerBufferSize.go test ./...passes.Note
This is the fix for the cause of the failure #129 reports. #129 makes the error visible (
Scanner.LastError()); this makes the game readable. They are independent and can land in either order.