Scanner ErrTooLong Raises Token Limit
Hit bufio.ErrTooLong on a line past the 64KiB default, then raise the cap with Scanner.Buffer so oversized records still parse.
Code
package main
import (
"bufio"
"fmt"
"strings"
)
func main() {
longLine := strings.Repeat("x", 70000)
input := longLine + "
short line
"
// the default token cap is 64KiB: the long line stops the scan with bufio.ErrTooLong
scanner := bufio.NewScanner(strings.NewReader(input))
for scanner.Scan() {
fmt.Println("token len:", len(scanner.Bytes()))
}
fmt.Println("first pass:", scanner.Err())
// Buffer raises the token limit: initial size, then maximum
scanner = bufio.NewScanner(strings.NewReader(input))
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
for scanner.Scan() {
fmt.Println("token len:", len(scanner.Bytes()))
}
fmt.Println("second pass:", scanner.Err())
}Inside the snippet
Scanner ErrTooLong Raises Token Limit comes down to the function main.
The file repeats itself only inside for scanner.Scan().
Watch out for
- No lockfile entry, no version pinning — the file needs nothing beyond the runtime.
Putting it to use
The run emits 3 labeled sections — token len:, first pass:, second pass: — one per step.
Core lines
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
Interactive Tools for This Topic
cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.LLM Token & Cost EstimatorEstimate BPE-approximate LLM token counts across English, CJK text, and source code and compare request and batch costs across pricing tiers.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does Scanner ErrTooLong Raises Token Limit print when run?
- Invoke the file as-is — the `token len:`, `first pass:`, `second pass:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.