golang/go · error
error parsing profile: %w
Error message
error parsing profile: %w
What it means
Thrown when profile.Parse fails to parse the input as a pprof-formatted profile, and the error is not profile.ErrNoData (which is handled separately as an empty profile). The %w wraps the underlying parse error from the github.com/google/pprof profile package. FromPProf is the entry point that converts a raw pprof protobuf into Go's internal PGO Profile representation.
Source
Thrown at src/cmd/internal/pgo/pprof.go:26
package pgo
import (
"errors"
"fmt"
"internal/profile"
"io"
"sort"
)
// FromPProf parses Profile from a pprof profile.
func FromPProf(r io.Reader) (*Profile, error) {
p, err := profile.Parse(r)
if errors.Is(err, profile.ErrNoData) {
// Treat a completely empty file the same as a profile with no
// samples: nothing to do.
return emptyProfile(), nil
} else if err != nil {
return nil, fmt.Errorf("error parsing profile: %w", err)
}
if len(p.Sample) == 0 {
// We accept empty profiles, but there is nothing to do.
return emptyProfile(), nil
}
valueIndex := -1
for i, s := range p.SampleType {
// Samples count is the raw data collected, and CPU nanoseconds is just
// a scaled version of it, so either one we can find is fine.
if (s.Type == "samples" && s.Unit == "count") ||
(s.Type == "cpu" && s.Unit == "nanoseconds") {
valueIndex = i
break
}
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Regenerate the CPU profile using a supported tool (go test -cpuprofile, pprof.CPUProfile, or runtime/pprof).
- Verify the file is a valid pprof profile by loading it with `go tool pprof <file>`.
- Check that the profile file is not truncated or corrupted (compare file size against expected, check gzip integrity).
- Ensure the file was not double-compressed or converted to a different encoding.
Example fix
// Regenerate a valid pprof profile: // go test -cpuprofile=cpu.prof -bench=. ./... // Then build with PGO: // go build -pgo=cpu.prof
Defensive patterns
Strategy: validation
Validate before calling
// Validate the file is a parseable pprof profile before feeding to PGO:
func validatePprof(path string) error {
f, err := os.Open(path)
if err != nil { return err }
defer f.Close()
// Use go tool pprof or the profile package to pre-validate
if _, err := profile.Parse(f); err != nil && !errors.Is(err, profile.ErrNoData) {
return fmt.Errorf("invalid pprof file: %w", err)
}
return nil
} Try / catch
// Wrap FromPProf and provide a clear diagnostic:
func safeFromPProf(r io.Reader) (*Profile, error) {
p, err := FromPProf(r)
if err != nil {
return nil, fmt.Errorf("PGO profile loading failed — ensure the file is a valid CPU pprof profile: %w", err)
}
return p, nil
} Prevention
- Always generate CPU profiles with go test -cpuprofile or runtime/pprof.StartCPUProfile.
- Verify the profile with `go tool pprof <file>` before using it for PGO builds.
- Do not pass arbitrary binary or text files as -pgo input.
When it happens
Trigger: profile.Parse(r) returns a non-nil error that is not ErrNoData. This covers corrupt protobuf data, truncated files, invalid pprof wire format, or I/O errors reading the input stream.
Common situations: Feeding a non-pprof file (e.g. a text file, ELF binary, or gzip-compressed data that isn't a pprof gzip stream) to the PGO compiler flag. Also occurs with truncated profiles from a crashed profiling session, or version-incompatible pprof protobuf schemas.
Related errors
- preprocessed profile error processing call line: %w
- preprocessed profile error processing call weight: %w
- profile does not contain a sample index with value/type "sam
- profile missing Function.start_line data (Go version of prof
- preprocessed profile entry missing weight
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/f5683dbbd90e27f9.
Report an issue: GitHub.