golang/go · error
error opening profile: %w
Error message
error opening profile: %w
What it means
The profile-guided optimization (PGO) subsystem opens a profile file via os.Open in pgoir.New(). This error wraps the underlying os.Open failure, which is typically a missing file, wrong path, or permission denied. The %w verb preserves the original error for unwrapping.
Source
Thrown at src/cmd/compile/internal/pgoir/irgraph.go:125
Callee *ir.Func
}
// Profile contains the processed PGO profile and weighted call graph used for
// PGO optimizations.
type Profile struct {
// Profile is the base data from the raw profile, without IR attribution.
*pgo.Profile
// WeightedCG represents the IRGraph built from profile, which we will
// update as part of inlining.
WeightedCG *IRGraph
}
// New generates a profile-graph from the profile or pre-processed profile.
func New(profileFile string) (*Profile, error) {
f, err := os.Open(profileFile)
if err != nil {
return nil, fmt.Errorf("error opening profile: %w", err)
}
defer f.Close()
r := bufio.NewReader(f)
isSerialized, err := pgo.IsSerialized(r)
if err != nil {
return nil, fmt.Errorf("error processing profile header: %w", err)
}
var base *pgo.Profile
if isSerialized {
base, err = pgo.FromSerialized(r)
if err != nil {
return nil, fmt.Errorf("error processing serialized PGO profile: %w", err)
}
} else {
base, err = pgo.FromPProf(r)
if err != nil {View on GitHub (pinned to b6b368adc5)
Solutions
- Verify the profile file exists at the specified path with os.Stat before building
- Use a path relative to the module root, or use an absolute path
- Regenerate the profile with: go test -cpuprofile=default.pgo ./...
- Check file permissions: ensure the build process can read the profile file
Defensive patterns
Strategy: validation
Validate before calling
// Verify PGO profile exists and is readable before building
import (
"os"
)
func validatePGOProfile(path string) error {
info, err := os.Stat(path)
if err != nil {
return fmt.Errorf("PGO profile not accessible: %w", err)
}
if info.Size() == 0 {
return fmt.Errorf("PGO profile is empty")
}
if !info.Mode().IsRegular() {
return fmt.Errorf("PGO profile is not a regular file")
}
return nil
} Prevention
- Check that the PGO profile file exists before running go build -pgo
- Use go test -cpuprofile to generate profiles rather than constructing them manually
- Store profile files in a predictable location relative to the module root
- Add the profile file to version control or a reliable artifact store in CI
When it happens
Trigger: Passing -pgo=/path/to/profile or -pgoprofile=/path where the file does not exist, is unreadable due to permissions, or the path is incorrect. The path can be absolute or relative to the working directory.
Common situations: CI pipelines where the PGO profile is not checked in or is generated in a different directory. Profile generation step failing or not running before the build step. Wrong working directory when the profile path is relative.
Related errors
- go:embed requires go1.16 or later (-lang was set to %s; chec
- error processing profile header: %w
- error processing serialized PGO profile: %w
- error processing pprof PGO profile: %w
- scanning %s: %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/7ed75e104a26ada7.
Report an issue: GitHub.