junegunn/fzf · error
could not create CPU profile: %w
Error message
could not create CPU profile: %w
What it means
In a pprof-enabled build (go build -tags=pprof), fzf failed to create the output file for the CPU profile given via --profile-cpu. The wrapped OS error (permission denied, no such directory, etc.) tells you why os.Create failed.
Source
Thrown at src/options_pprof.go:19
//go:build pprof
// +build pprof
package fzf
import (
"fmt"
"os"
"runtime"
"runtime/pprof"
"github.com/junegunn/fzf/src/util"
)
func (o *Options) initProfiling() error {
if o.CPUProfile != "" {
f, err := os.Create(o.CPUProfile)
if err != nil {
return fmt.Errorf("could not create CPU profile: %w", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
return fmt.Errorf("could not start CPU profile: %w", err)
}
util.AtExit(func() {
pprof.StopCPUProfile()
if err := f.Close(); err != nil {
fmt.Fprintln(os.Stderr, "Error: closing cpu profile:", err)
}
})
}
stopProfile := func(name string, f *os.File) {
if err := pprof.Lookup(name).WriteTo(f, 0); err != nil {
fmt.Fprintf(os.Stderr, "Error: could not write %s profile: %v\n", name, err)
}View on GitHub (pinned to bd4efa277b)
Solutions
- Create the parent directory first: mkdir -p /tmp/prof
- Point --profile-cpu at an existing writable directory
- Check the wrapped error text for the exact OS reason
Example fix
# before fzf --profile-cpu /nonexistent/cpu.prof # after mkdir -p /tmp/prof && fzf --profile-cpu /tmp/prof/cpu.prof
Defensive patterns
Strategy: validation
Validate before calling
prof_dir=/tmp/fzf-prof; mkdir -p "$prof_dir" && [ -w "$prof_dir" ] || exit 1 fzf --profile-cpu "$prof_dir/cpu.prof"
Prevention
- mkdir -p the profile directory in the same command
- Use absolute paths so cwd changes cannot break profiling
When it happens
Trigger: Passing --profile-cpu /path/cpu.prof where the directory does not exist, is not writable, or the path is a directory itself; initProfiling runs during option initialization and aborts startup.
Common situations: Profiling into a temp dir that was cleaned up; profiling paths with typos; running as a user without write access to the target directory.
Related errors
- failed to start pprof profiles: %s
- could not create MEM profile: %w
- could not create BLOCK profile: %w
- could not create MUTEX profile: %w
- error: profiling not supported: FZF must be built with '-tag
AI-assisted analysis of junegunn/fzf@bd4efa277b (2026-08-15).
Data as JSON: /api/errors/4846d4e5108d489a.
Report an issue: GitHub.