golang/go · error
error reading preprocessed profile: %w
Error message
error reading preprocessed profile: %w
What it means
In FromSerialized, the very first scanner.Scan() returned false (no token) AND scanner.Err() is non-nil — i.e. an I/O or scanner error occurred while reading the header line, distinct from a clean empty file (1276) or a wrong header (1277).
Source
Thrown at src/cmd/internal/pgo/deserialize.go:40
// Empty file.
return false, nil
} else if err != nil {
return false, fmt.Errorf("error reading profile header: %w", err)
}
return string(hdr) == serializationHeader, nil
}
// FromSerialized parses a profile from serialization output of Profile.WriteTo.
func FromSerialized(r io.Reader) (*Profile, error) {
d := emptyProfile()
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)
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 missing header")
}
if gotHdr := scanner.Text() + "\n"; gotHdr != serializationHeader {
return nil, fmt.Errorf("preprocessed profile malformed header; got %q want %q", gotHdr, serializationHeader)
}
for scanner.Scan() {
readStr := scanner.Text()
callerName := readStr
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 callee")
}View on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the profile with Profile.WriteTo to ensure it is well-formed.
- If lines may be long, supply a scanner with a larger buffer.
- Verify the file is complete and not truncated.
Defensive patterns
Strategy: validation
Validate before calling
// Confirm non-empty and well-formed before FromSerialized.
// fi, err := os.Stat(path)
// if err != nil { return err }
// if fi.Size() == 0 { return errors.New("profile empty") } Try / catch
// prof, err := pgo.FromSerialized(r)
// if err != nil && strings.Contains(err.Error(), "error reading preprocessed profile") {
// // I/O error on header; regenerate the profile
// return err
// } Prevention
- Regenerate profiles with Profile.WriteTo.
- Supply a scanner with a larger buffer if header lines may be long.
- Verify the profile file is complete before parsing.
When it happens
Trigger: bufio.Scanner returns an error on the first Scan call against the profile stream — e.g. a line longer than the scanner buffer, or an underlying read error.
Common situations: A profile with an extremely long header line exceeding the default scanner token limit, or a corrupted/partially-flushed profile file.
Related errors
- error reading profile header: %w
- error opening target for caching: %w
- error adding target to cache: %w
- preprocessed profile missing header
- preprocessed profile malformed header; got %q want %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/6fa7558f6575fbfb.
Report an issue: GitHub.