golang/go · error

scanning %s: %v

Error message

scanning %s: %v

What it means

The SSA backend reads source files via readFuncLines to obtain line-by-line content for debug position information. It uses bufio.Scanner which has a default maximum token (line) size of 64*1024 bytes. This error wraps any scanner.Err() failure, most commonly bufio.ErrTooLong when a single line exceeds the buffer limit.

Source

Thrown at src/cmd/compile/internal/ssagen/ssa.go:978

}

func readFuncLines(file string, start, end uint) (*ssa.FuncLines, error) {
	f, err := os.Open(os.ExpandEnv(file))
	if err != nil {
		return nil, err
	}
	defer f.Close() // ignore error
	var lines []string
	ln := uint(1)
	scanner := bufio.NewScanner(f)
	for scanner.Scan() && ln <= end {
		if ln >= start {
			lines = append(lines, scanner.Text())
		}
		ln++
	}
	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("scanning %s: %v", file, err)
	}
	return &ssa.FuncLines{Filename: file, StartLineno: start, Lines: lines}, nil
}

// updateUnsetPredPos propagates the earliest-value position information for b
// towards all of b's predecessors that need a position, and recurs on that
// predecessor if its position is updated. B should have a non-empty position.
func (s *state) updateUnsetPredPos(b *ssa.Block) {
	if b.Pos == src.NoXPos {
		s.Fatalf("Block %s should have a position", b)
	}
	bestPos := src.NoXPos
	for _, e := range b.Preds {
		p := e.Block()
		if !p.LackingPos() {
			continue
		}
		if bestPos == src.NoXPos {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Split very long lines into multiple shorter lines in the source file
  2. Configure your code generator to produce output with reasonable line lengths
  3. Move large embedded data to separate files and use //go:embed instead of inline string literals
  4. If generating Go code, insert newlines after each statement or struct field

Example fix

// before (single line)
var data = "<base64 string that is 100KB long>"

// after (split across lines)
var data = "<chunk1>" +
    "<chunk2>" +
    "<chunk3>"
Defensive patterns

Strategy: validation

Validate before calling

// Check for excessively long lines in Go source files
import (
    "bufio"
    "os"
)

func checkLongLines(path string, maxLineLen int) error {
    f, err := os.Open(path)
    if err != nil {
        return err
    }
    defer f.Close()
    scanner := bufio.NewScanner(f)
    scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024) // allow up to 1MB lines for scanning
    lineNum := 0
    for scanner.Scan() {
        lineNum++
        if len(scanner.Bytes()) > maxLineLen {
            return fmt.Errorf("%s:%d: line length %d exceeds %d bytes", path, lineNum, len(scanner.Bytes()), maxLineLen)
        }
    }
    return scanner.Err()
}

// Usage: checkLongLines(file, 64*1024) before building

Prevention

When it happens

Trigger: A Go source file containing a single line longer than 64KB (the bufio.Scanner default buffer size). Machine-generated Go files with enormous string literals, base64 blobs, or embedded data on a single line. Files with missing newlines.

Common situations: Code generators that emit very long lines (e.g., stringified JSON, base64-encoded images). go:generate tools that produce single-line output. Minified or machine-written Go files. Files with very long //go:embed or import lists.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/cf44ececde541ad6. Report an issue: GitHub.