junegunn/fzf · error
invalid duration for --bench: %s
Error message
invalid duration for --bench: %s
What it means
fzf failed to parse the value passed to --bench as a Go duration. The value is passed straight to time.ParseDuration, so it must use Go duration syntax (e.g. 3s, 500ms, 1m10s). Note the error message wraps the parse failure with the offending string, replacing the underlying Go error text.
Source
Thrown at src/options.go:3459
if err != nil {
return err
}
opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))
case "--threads":
if opts.Threads, err = nextInt("number of threads required"); err != nil {
return err
}
if opts.Threads < 0 {
return errors.New("--threads must be a positive integer")
}
case "--bench":
str, err := nextString("duration required (e.g. 3s, 500ms)")
if err != nil {
return err
}
dur, err := time.ParseDuration(str)
if err != nil {
return errors.New("invalid duration for --bench: " + str)
}
opts.Bench = dur
case "--profile-cpu":
if opts.CPUProfile, err = nextString("file path required: cpu"); err != nil {
return err
}
case "--profile-mem":
if opts.MEMProfile, err = nextString("file path required: mem"); err != nil {
return err
}
case "--profile-block":
if opts.BlockProfile, err = nextString("file path required: block"); err != nil {
return err
}
case "--profile-mutex":
if opts.MutexProfile, err = nextString("file path required: mutex"); err != nil {
return err
}View on GitHub (pinned to bd4efa277b)
Solutions
- Use a valid Go duration literal: --bench 3s, --bench 500ms, --bench 1m
- If scripting, validate with time.ParseDuration before invoking fzf
- Check that no stray characters or unit suffixes like 'sec' are appended
Example fix
# before fzf --bench 100 # after fzf --bench 100ms
Defensive patterns
Strategy: validation
Validate before calling
// Go: validate before exec
if _, err := time.ParseDuration(benchFlag); err != nil {
log.Fatalf("--bench must be a Go duration like 3s or 500ms: %v", err)
}
_ = exec.Command("fzf", "--bench", benchFlag).Run() Type guard
func isValidGoDuration(s string) bool { _, err := time.ParseDuration(s); return err == nil } Try / catch
In Go, check err from fzf's exit (exec.ExitError stderr) and if it mentions 'invalid duration for --bench', print the accepted syntax and re-prompt for the value.
Prevention
- Always use Go duration units (s, ms, m)
- Validate duration strings with time.ParseDuration before building the fzf command line
- Centralize fzf flags in one config builder to review units once
When it happens
Trigger: Running fzf with --bench set to a bare number (e.g. --bench 3 instead of --bench 3s), or a non-duration string (e.g. --bench fast). The case block in options.go:3459 calls nextString then time.ParseDuration(str) and returns this error on any parse failure.
Common situations: Users used to millisecond counts (--bench 100) or second-only integers; copying benchmark flags from other tools that accept bare numbers; typos like '3sec' instead of '3s'.
Related errors
- at least one of 'file' or 'dir' should be specified
- unable to put non-printable character
- unknown action: ${spec}
- key name required
- bind action not specified: ${keys}
AI-assisted analysis of junegunn/fzf@bd4efa277b (2026-08-15).
Data as JSON: /api/errors/7121e4af2e6cfc89.
Report an issue: GitHub.