feat(OutputBuffer): expose scanner buffer size configuration#1
Open
sherlant wants to merge 3 commits into
Open
feat(OutputBuffer): expose scanner buffer size configuration#1sherlant wants to merge 3 commits into
sherlant wants to merge 3 commits into
Conversation
added 3 commits
May 13, 2026 16:15
OutputBuffer.Lines() used bufio.NewScanner with its default 64KB token limit. Lines exceeding that size caused silent truncation: s.Scan() returned false with bufio.ErrTooLong, but the error was never checked, so all subsequent output was lost without any indication. - Adds SetScannerBufferSize(n int) on OutputBuffer to override the limit - Adds Err() on OutputBuffer to surface scanner errors to callers - Propagates Options.LineBufferSize (already used by OutputStream) to OutputBuffer in NewCmdOptions, for both Buffered and CombinedOutput modes - Propagates the buffer size through Clone() - Adds tests covering the truncation behaviour and the new API
When OutputBuffer.Lines() encounters a line exceeding the scanner buffer size, the error is now surfaced in Status.Error once the command finishes, so callers using the Cmd API detect the truncation without having to access OutputBuffer directly.
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
OutputBuffer.Lines()usesbufio.NewScannerwith its default 64KB token limit. When a line exceeds that size,s.Scan()returnsfalsewithbufio.ErrTooLong, but the error was never checked — causing silent truncation of all subsequent output with no indication of failure.Options.LineBufferSizealready existed forOutputStreambut was not propagated toOutputBuffer, making it impossible to work around this issue.Changes
OutputBuffer.SetScannerBufferSize(n int)— sets the maximum token size for the internalbufio.Scanner; default remainsbufio.MaxScanTokenSize(64KB) for backwards compatibilityOutputBuffer.Err() error— surfaces any scanner error (e.g.bufio.ErrTooLong) to the callerOptions.LineBufferSizeis now propagated toOutputBufferinNewCmdOptions, for bothBufferedandCombinedOutputmodesClone()propagates the configured buffer size to the clonedCmdOptions.LineBufferSizepropagation, andClone()propagationTest plan
go test ./...passes (32 tests)TestOutputBufferLongLineTruncation— verifiesErr()is set on overflowTestOutputBufferSetScannerBufferSize— verifies large lines work after enlarging the bufferTestOutputBufferLineBufferSizeOption— verifiesOptions.LineBufferSizereachesOutputBufferTestOutputBufferClonePropagatesScannerBufSize— verifiesClone()preserves the setting