junegunn/fzf · error

could not create MEM profile: %w

Error message

could not create MEM profile: %w

What it means

In a pprof build, fzf could not create the memory-profile output file specified by --profile-mem. os.Create failed and the wrapped error carries the OS-level reason; startup aborts before the memory profile is registered.

Source

Thrown at src/options_pprof.go:46

			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)
		}
		if err := f.Close(); err != nil {
			fmt.Fprintf(os.Stderr, "Error: closing %s profile: %v\n", name, err)
		}
	}

	if o.MEMProfile != "" {
		f, err := os.Create(o.MEMProfile)
		if err != nil {
			return fmt.Errorf("could not create MEM profile: %w", err)
		}
		util.AtExit(func() {
			runtime.GC()
			stopProfile("allocs", f)
		})
	}

	if o.BlockProfile != "" {
		runtime.SetBlockProfileRate(1)
		f, err := os.Create(o.BlockProfile)
		if err != nil {
			return fmt.Errorf("could not create BLOCK profile: %w", err)
		}
		util.AtExit(func() { stopProfile("block", f) })
	}

	if o.MutexProfile != "" {
		runtime.SetMutexProfileFraction(1)

View on GitHub (pinned to bd4efa277b)

Solutions

  1. mkdir -p the target directory
  2. Use an absolute path under a writable location like /tmp
  3. Verify with touch on the exact path before rerunning

Example fix

# before
fzf --profile-mem /run/mem.prof   # /run not writable
# after
fzf --profile-mem /tmp/mem.prof
Defensive patterns

Strategy: validation

Validate before calling

mkdir -p /tmp/fzf-prof && touch /tmp/fzf-prof/mem.prof 2>/dev/null || exit 1
fzf --profile-mem /tmp/fzf-prof/mem.prof

Prevention

When it happens

Trigger: Passing --profile-mem with a path whose directory is missing or unwritable, or naming an existing directory as the file.

Common situations: Same shape as other profile-path errors: stale temp dirs, permission-restricted output dirs, typos in the flag value.

Related errors


AI-assisted analysis of junegunn/fzf@bd4efa277b (2026-08-15). Data as JSON: /api/errors/d144d60de8a816f2. Report an issue: GitHub.