muesli/duf · error
'%s' is not valid, must have integer with optional SI prefix
Error message
'%s' is not valid, must have integer with optional SI prefix
What it means
stringToSize parses an SI size string like "10G" into a byte count. The input must match ^\d+([KMGTPE]?)$; if it does not, the function returns "'%s' is not valid, must have integer with optional SI prefix". This validates the shape of threshold size values before applying the prefix multiplier.
Source
Thrown at table.go:508
case size >= 1<<30:
str = fmt.Sprintf("%.1fG", b/(1<<30))
case size >= 1<<20:
str = fmt.Sprintf("%.1fM", b/(1<<20))
case size >= 1<<10:
str = fmt.Sprintf("%.1fK", b/(1<<10))
default:
str = fmt.Sprintf("%dB", size)
}
return
}
// stringToSize transforms an SI size into a number.
func stringToSize(s string) (size uint64, err error) {
regex := regexp.MustCompile(`^(\d+)([KMGTPE]?)$`)
matches := regex.FindStringSubmatch(s)
if len(matches) == 0 {
return 0, fmt.Errorf("'%s' is not valid, must have integer with optional SI prefix", s)
}
num, err := strconv.ParseUint(matches[1], 10, 64)
if err != nil {
return 0, err
}
if matches[2] != "" {
prefix := matches[2]
switch prefix {
case "K":
size = num << 10
case "M":
size = num << 20
case "G":
size = num << 30
case "T":
size = num << 40
case "P":View on GitHub (pinned to 4636deb4a7)
Solutions
- Use the format <integer><optional uppercase SI prefix>, e.g. "10", "10G", "2T".
- Convert decimals to whole units (1.5G -> 1536M).
- Use uppercase K/M/G/T/P/E; lowercase k is rejected.
Example fix
// before
stringToSize("1.5G")
// after
stringToSize("1536M") Defensive patterns
Strategy: validation
Validate before calling
var sizeRe = regexp.MustCompile(`^\d+([KMGTPE]?)$`)
func validSize(s string) bool { return sizeRe.MatchString(s) } Try / catch
size, err := stringToSize(input)
if err != nil {
return fmt.Errorf("bad size %q: %w", input, err)
} Prevention
- Format sizes as integer plus optional uppercase SI prefix (10G, 2T).
- Convert decimals (1.5G) to whole smaller units (1536M).
- Never use lowercase prefixes or IEC suffixes like Gi/MiB.
When it happens
Trigger: Calling stringToSize (directly or via --avail-threshold parsing) with strings like "10Gi", "1.5G", "10k" (lowercase), "G10", or an empty string — anything failing the digit-plus-optional-uppercase-prefix regex.
Common situations: Users write decimal sizes (1.5G), IEC suffixes (Gi, MiB), lowercase prefixes (10k), or reversed order (G10) in threshold flags.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E
- unknown style option: %s
- unknown device group: %s
- error parsing avail-threshold: invalid option '%s'
- error parsing usage-threshold: invalid option '%s'
AI-assisted analysis of muesli/duf@4636deb4a7 (2026-09-06).
Data as JSON: /api/errors/47801e17481e45c6.
Report an issue: GitHub.