Skip to content

feat(OutputBuffer): expose scanner buffer size configuration#1

Open
sherlant wants to merge 3 commits into
masterfrom
feat/output-buffer-scanner-buf-size
Open

feat(OutputBuffer): expose scanner buffer size configuration#1
sherlant wants to merge 3 commits into
masterfrom
feat/output-buffer-scanner-buf-size

Conversation

@sherlant

Copy link
Copy Markdown
Collaborator

Problem

OutputBuffer.Lines() uses bufio.NewScanner with its default 64KB token limit. When a line exceeds that size, s.Scan() returns false with bufio.ErrTooLong, but the error was never checked — causing silent truncation of all subsequent output with no indication of failure.

Options.LineBufferSize already existed for OutputStream but was not propagated to OutputBuffer, making it impossible to work around this issue.

Changes

  • OutputBuffer.SetScannerBufferSize(n int) — sets the maximum token size for the internal bufio.Scanner; default remains bufio.MaxScanTokenSize (64KB) for backwards compatibility
  • OutputBuffer.Err() error — surfaces any scanner error (e.g. bufio.ErrTooLong) to the caller
  • Options.LineBufferSize is now propagated to OutputBuffer in NewCmdOptions, for both Buffered and CombinedOutput modes
  • Clone() propagates the configured buffer size to the cloned Cmd
  • Tests covering: normal lines, truncation detection, enlarged buffer, Options.LineBufferSize propagation, and Clone() propagation

Test plan

  • go test ./... passes (32 tests)
  • TestOutputBufferLongLineTruncation — verifies Err() is set on overflow
  • TestOutputBufferSetScannerBufferSize — verifies large lines work after enlarging the buffer
  • TestOutputBufferLineBufferSizeOption — verifies Options.LineBufferSize reaches OutputBuffer
  • TestOutputBufferClonePropagatesScannerBufSize — verifies Clone() preserves the setting

steeven.herlant 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.
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