junegunn/fzf · error

invalid ${opt}: ${margin}

Error message

invalid ${opt}: ${margin}

What it means

Thrown by parseMargin (used for --margin, --padding, --border-* padding forms) when the value has 4 comma-separated parts (TRBL form) but one of them fails the per-part check, or when the overall shape does not match the accepted 1/2/4-part forms and number ranges. The message interpolates the option name and the offending raw value.

Source

Thrown at src/options.go:2485

		t, e := checked(margins[0])
		if e != nil {
			return defaultMargin(), e
		}
		r, e := checked(margins[1])
		if e != nil {
			return defaultMargin(), e
		}
		b, e := checked(margins[2])
		if e != nil {
			return defaultMargin(), e
		}
		l, e := checked(margins[3])
		if e != nil {
			return defaultMargin(), e
		}
		return [4]sizeSpec{t, r, b, l}, nil
	}
	return [4]sizeSpec{}, errors.New("invalid " + opt + ": " + margin)
}

func parseMarkerMultiLine(str string) (*[3]string, error) {
	if str == "" {
		return &[3]string{}, nil
	}
	gr := uniseg.NewGraphemes(str)
	parts := []string{}
	totalWidth := 0
	for gr.Next() {
		s := string(gr.Runes())
		totalWidth += uniseg.StringWidth(s)
		parts = append(parts, s)
	}

	result := [3]string{}
	if totalWidth != 3 && totalWidth != 6 {
		return &result, fmt.Errorf("invalid total marker width: %d (expected: 0, 3 or 6)", totalWidth)

View on GitHub (pinned to bd4efa277b)

Solutions

  1. Use 1, 2, or 4 comma-separated values only: 'M', 'V,H', 'T,R,B,L'
  2. Ensure every component is a non-negative integer or percent (e.g. '5%')
  3. Log/echo the generated margin string before invoking fzf to spot empty components

Example fix

# before
fzf --margin '1,2,3'
# after
fzf --margin '1,2,3,4'
Defensive patterns

Strategy: validation

Validate before calling

# bash: 1, 2, or 4 non-negative parts
margin_ok() {
  IFS=',' read -ra p <<< "$1"
  (( ${#p[@]} == 1 || ${#p[@]} == 2 || ${#p[@]} == 4 )) || return 1
  for x in "${p[@]}"; do [[ "$x" =~ ^[0-9]+%?$ ]] || return 1; done
}
margin_ok "$MARGIN" || MARGIN="0"

Prevention

When it happens

Trigger: `--margin '1,2,3,4,5'` (five parts), `--margin '1,-2'` (negative), `--padding 'a,b'` (non-numeric), or a 3-part margin like '1,2,3' which is not a valid shape.

Common situations: Copy-pasting CSS-style shorthand (which allows 3 values) into fzf; script-built margin strings with an empty component from an unset variable; expecting '1 2 3 4' space-separated to work.

Related errors


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