junegunn/fzf · error

${label} (without %) must be a non-negative integer

Error message

${label} (without %) must be a non-negative integer

What it means

Thrown by parseSize for non-percent inputs. Without a trailing '%', the value must be a plain non-negative integer (parsed via atoi); a decimal point in the string (e.g. '1.5') is rejected outright with this message before atoi is attempted.

Source

Thrown at src/options.go:2243

func parseSize(str string, maxPercent float64, label string) (sizeSpec, error) {
	var spec = sizeSpec{}
	var val float64
	var err error
	percent := strings.HasSuffix(str, "%")
	if percent {
		if val, err = atof(str[:len(str)-1]); err != nil {
			return spec, err
		}

		if val < 0 {
			return spec, errors.New(label + " must be non-negative")
		}
		if val > maxPercent {
			return spec, fmt.Errorf("%s too large (max: %d%%)", label, int(maxPercent))
		}
	} else {
		if strings.Contains(str, ".") {
			return spec, errors.New(label + " (without %) must be a non-negative integer")
		}

		i, err := atoi(str)
		if err != nil {
			return spec, err
		}
		val = float64(i)
		if val < 0 {
			return spec, errors.New(label + " must be non-negative")
		}
	}
	return sizeSpec{val, percent}, nil
}

func parseHeight(str string, index int) (heightSpec, error) {
	heightSpec := heightSpec{index: index}
	if strings.HasPrefix(str, "~") {
		heightSpec.auto = true

View on GitHub (pinned to bd4efa277b)

Solutions

  1. Round or truncate computed values to integers: use printf '%.0f' or awk int(...)
  2. Use the '%' form if fractional values are intended, since percent parsing uses atof

Example fix

# before
fzf --height "$(echo "$LINES*0.4" | bc -l)"
# after
fzf --height "$(awk "BEGIN{printf \"%d\", $LINES*0.4}")"
Defensive patterns

Strategy: validation

Validate before calling

# bash: non-percent sizes must be plain integers
[[ "$SIZE" =~ ^[0-9]+$ ]] || { echo "size must be an integer" >&2; exit 1; }
fzf --height "$SIZE"

Prevention

When it happens

Trigger: `--height 1.5`, `--min-height 10.25`, `--preview-window right:50.5` — any non-percent size containing a '.'.

Common situations: Dividing sizes in shell with bc/awk (which emit decimals) and feeding the result straight to fzf; assuming fractional line counts are allowed because the %-form accepts fractional numbers via atof.

Related errors


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