muesli/duf · error

error parsing avail-threshold: invalid option '%s'

Error message

error parsing avail-threshold: invalid option '%s'

What it means

main validates the --avail-threshold flag, which must contain exactly two comma-separated size values (e.g. "10G,20G"). If splitting on "," does not yield exactly two parts, the program prints "error parsing avail-threshold: invalid option '%s'" to stderr and exits with status 1.

Source

Thrown at main.go:311

				fmt.Println(err)
				os.Exit(1)
			}
			// de-duplicate
			for _, v := range fm {
				if _, ok := vis[v.Mountpoint]; !ok {
					mounts = append(mounts, v)
					vis[v.Mountpoint] = struct{}{}
				}
			}
		}

		m = mounts
	}

	// validate availability thresholds
	availbilityThresholds := strings.Split(*availThreshold, ",")
	if len(availbilityThresholds) != 2 {
		fmt.Fprintln(os.Stderr, fmt.Errorf("error parsing avail-threshold: invalid option '%s'", *availThreshold))
		os.Exit(1)
	}
	for _, threshold := range availbilityThresholds {
		_, err = stringToSize(threshold)
		if err != nil {
			fmt.Fprintln(os.Stderr, "error parsing avail-threshold:", err)
			os.Exit(1)
		}
	}

	// validate usage thresholds
	usageThresholds := strings.Split(*usageThreshold, ",")
	if len(usageThresholds) != 2 {
		fmt.Fprintln(os.Stderr, fmt.Errorf("error parsing usage-threshold: invalid option '%s'", *usageThreshold))
		os.Exit(1)
	}
	for _, threshold := range usageThresholds {
		_, err = strconv.ParseFloat(threshold, 64)

View on GitHub (pinned to 4636deb4a7)

Solutions

  1. Supply exactly two comma-separated sizes, e.g. --avail-threshold "10G,20G".
  2. Remove trailing/leading commas or spaces that create empty segments.
  3. Quote the value in shell scripts so commas are not misinterpreted.

Example fix

// before
--avail-threshold 10G
// after
--avail-threshold "10G,20G"
Defensive patterns

Strategy: validation

Validate before calling

parts := strings.Split(availThreshold, ",")
if len(parts) != 2 {
	return fmt.Errorf("avail-threshold needs exactly 2 values")
}
for _, p := range parts {
	if _, err := regexp.MatchString(`^\d+[KMGTPE]?$`, p); err != nil { /* invalid */ }
}

Try / catch

if err := validateAvailThreshold(flag); err != nil {
	fmt.Fprintln(os.Stderr, err)
	os.Exit(1)
}

Prevention

When it happens

Trigger: Running with --avail-threshold that has zero or one comma-separated part (e.g. "10G", "", "10G,20G,30G"), or an empty default flag value.

Common situations: Users pass a single threshold thinking one value suffices, include stray spaces or extra commas, or leave the flag empty in scripts.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of muesli/duf@4636deb4a7 (2026-09-06). Data as JSON: /api/errors/87d34fa4db6af478. Report an issue: GitHub.