muesli/duf · error

prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E

Error message

prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E

What it means

After the numeric part of a size string parses, stringToSize switches on the SI prefix. Although the regex only admits K/M/G/T/P/E or empty, if the prefix somehow reaches the default case the function returns "prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E". This is a defensive guard listing the valid multipliers.

Source

Thrown at table.go:531

		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":
			size = num << 50
		case "E":
			size = num << 60
		default:
			err = fmt.Errorf("prefix '%s' not allowed, valid prefixes are K, M, G, T, P, E", prefix)
			return
		}
	} else {
		size = num
	}
	return
}

// stringToColumn converts a column name to its index.
func stringToColumn(s string) (int, error) {
	s = strings.ToLower(s)

	for i, v := range columns {
		if v.ID == s {
			return i + 1, nil
		}
	}

View on GitHub (pinned to 4636deb4a7)

Solutions

  1. Use one of the supported uppercase prefixes: K, M, G, T, P, E.
  2. If the validation regex was modified, restore ^\d+([KMGTPE]?)$ or add matching switch cases.
  3. Convert IEC units (KiB/MiB) to the supported SI prefixes.

Example fix

// before
case "k": size = num << 10 // lowercase unsupported upstream
// after
case "K": size = num << 10
Defensive patterns

Strategy: validation

Validate before calling

validPrefixes := map[string]bool{"K": true, "M": true, "G": true, "T": true, "P": true, "E": true, "": true}
if !validPrefixes[prefix] { /* reject before calling */ }

Try / catch

size, err := stringToSize(input)
if err != nil {
	return fmt.Errorf("bad prefix in %q: %w", input, err)
}

Prevention

When it happens

Trigger: stringToSize receives a size token whose prefix fails the shift-based switch — practically unreachable via the public regex, but reachable if the regex is relaxed/modified or the function is refactored to accept arbitrary prefixes.

Common situations: Hitting this after code changes that loosen the validation regex (e.g. allowing lowercase or IEC prefixes) without updating the switch; users seeing it from custom builds.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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