golang/go · error
preprocessed profile entry got %v want 2 fields
Error message
preprocessed profile entry got %v want 2 fields
What it means
Thrown when the third line of a preprocessed PGO profile edge entry (the weight line) does not split into exactly 2 space-separated fields. The deserializer expects "<call-site-offset> <weight>" but strings.Split produced a different count — meaning the line has extra spaces, missing a field, or has a different delimiter.
Source
Thrown at src/cmd/internal/pgo/deserialize.go:72
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("error reading preprocessed profile: %w", err)
}
return nil, fmt.Errorf("preprocessed profile entry missing callee")
}
calleeName := scanner.Text()
if !scanner.Scan() {
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("error reading preprocessed profile: %w", err)
}
return nil, fmt.Errorf("preprocessed profile entry missing weight")
}
readStr = scanner.Text()
split := strings.Split(readStr, " ")
if len(split) != 2 {
return nil, fmt.Errorf("preprocessed profile entry got %v want 2 fields", split)
}
co, err := strconv.Atoi(split[0])
if err != nil {
return nil, fmt.Errorf("preprocessed profile error processing call line: %w", err)
}
edge := NamedCallEdge{
CallerName: callerName,
CalleeName: calleeName,
CallSiteOffset: co,
}
weight, err := strconv.ParseInt(split[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("preprocessed profile error processing call weight: %w", err)
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the profile with the matching Go toolchain to ensure the exact "offset weight" space-separated format.
- Inspect the raw weight line bytes for tabs, multiple spaces, or missing fields and fix the serialization.
- Ensure no editor or CI step reflows whitespace in the profile file.
Example fix
// The weight line must be exactly: "<int> <int>" // Before (broken): "42 1000" (double space -> 3 fields after split) // After (fixed): "42 1000"
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate that every third line has exactly 2 space-separated fields:
func validateWeightLines(path string) error {
data, err := os.ReadFile(path)
if err != nil { return err }
lines := strings.Split(strings.TrimRight(string(data), "\n"), "\n")
for i := 2; i < len(lines); i += 3 {
fields := strings.Split(lines[i], " ")
if len(fields) != 2 {
return fmt.Errorf("line %d: expected 2 fields, got %d", i+1, len(fields))
}
}
return nil
} Prevention
- Never edit preprocessed profile files manually — regenerate from source.
- Ensure the serializer uses a single space between offset and weight.
- Validate the weight-line format before deserialization.
When it happens
Trigger: strings.Split(readStr, " ") on the weight line yields a slice whose length is not 2. This happens when the line has zero spaces (single field), multiple spaces (3+ fields after split), leading/trailing spaces, or uses a different separator like a tab.
Common situations: Profile serialized by a tool that used tab separators instead of spaces, or a tool that emitted extra metadata fields on the weight line. Also occurs if the file was reformatted or had whitespace stripped/added by an editor or version-control system.
Related errors
- preprocessed profile entry missing weight
- preprocessed profile error processing call line: %w
- preprocessed profile error processing call weight: %w
- preprocessed profile contains duplicate edge %+v
- error parsing profile: %w
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/4cc53af63b761055.
Report an issue: GitHub.