junegunn/fzf · error

invalid format: ${str}

Error message

invalid format: ${str}

What it means

First rejection point in splitNth: the input to an nth-selecting option (--nth in range form) must match ^[0-9,-.]+$ before parsing. Anything containing other characters — letters, spaces, quotes — fails immediately with 'invalid format'.

Source

Thrown at src/options.go:842

func atoi(str string) (int, error) {
	num, err := strconv.Atoi(str)
	if err != nil {
		return 0, errors.New("not a valid integer: " + str)
	}
	return num, nil
}

func atof(str string) (float64, error) {
	num, err := strconv.ParseFloat(str, 64)
	if err != nil {
		return 0, errors.New("not a valid number: " + str)
	}
	return num, nil
}

func splitNth(str string) ([]Range, error) {
	if match, _ := regexp.MatchString("^[0-9,-.]+$", str); !match {
		return nil, errors.New("invalid format: " + str)
	}

	tokens := strings.Split(str, ",")
	ranges := make([]Range, len(tokens))
	for idx, s := range tokens {
		r, ok := ParseRange(&s)
		if !ok {
			return nil, errors.New("invalid format: " + str)
		}
		ranges[idx] = r
	}
	return ranges, nil
}

func nthTransformer(str string) (func(Delimiter) func([]Token, int32) string, error) {
	// ^[0-9,-.]+$"
	if match, _ := regexp.MatchString("^[0-9,-.]+$", str); match {
		nth, err := splitNth(str)

View on GitHub (pinned to bd4efa277b)

Solutions

  1. Rewrite the --nth value using only digits, commas, hyphens and dots: --nth 1,3-5
  2. Fix shell quoting so quotes/spaces are not part of the value
  3. Use '..' ranges in the supported form 1..3 (dots are allowed by the regex) or 1-3
  4. For regex/field matching use --nth with fzf's field regex syntax only where documented (e.g. --nth ,.. for last field)

Example fix

# before
fzf --nth '1, 3-5'
# after
fzf --nth 1,3-5
Defensive patterns

Strategy: validation

Validate before calling

NTH='1,3-5'
[[ "$NTH" =~ ^[0-9.,-]+$ ]] || { echo "bad --nth: $NTH" >&2; exit 1; }
fzf --nth "$NTH"

Prevention

When it happens

Trigger: Calling fzf --nth '1,3-5' is fine; --nth '1, 3' (space), --nth '1..3' style mistakes are fine, but --nth 'foo', --nth '"1"' (embedded quotes), or --nth '1;' fails this regex gate.

Common situations: Shell quoting mistakes that leak quote characters into the value; using Haskell-style '..' separators or regex-ish syntax fzf does not support; trailing semicolons from copy-pasted commands.

Related errors


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