probelabs/goreplay · error

invalid _len %q

Error message

invalid _len %q

What it means

Size.Set parses a human-readable data-unit string (e.g. '10KB', '2MB') using unit suffix matchers; if the string ends in a suffix no matcher recognizes, it returns fmt.Errorf("invalid _len %q", size). This means the input did not match any supported unit (B, KB, MB, GB, TB, etc.).

Source

Thrown at internal/size/size.go:56

	var _len int64
	switch {
	case rB.Match(s):
		_len, err = strconv.ParseInt(size, 0, 64)
	case rKB.Match(s):
		_len, err = strconv.ParseInt(size[:lmt], 0, 64)
		_len *= KB
	case rMB.Match(s):
		_len, err = strconv.ParseInt(size[:lmt], 0, 64)
		_len *= MB
	case rGB.Match(s):
		_len, err = strconv.ParseInt(size[:lmt], 0, 64)
		_len *= GB
	case rTB.Match(s):
		_len, err = strconv.ParseInt(size[:lmt], 0, 64)
		_len *= TB
	default:
		return fmt.Errorf("invalid _len %q", size)
	}
	*siz = Size(_len)
	return
}

func (siz *Size) String() string {
	return fmt.Sprintf("%d", *siz)
}

View on GitHub (pinned to 251e45abd2)

Solutions

  1. Use a supported unit suffix exactly as accepted by the parser (e.g. B, KB, MB, GB, TB with matching case).
  2. Check the regex set in internal/size/size.go and conform the input to it.
  3. Pre-normalize input (trim spaces, canonicalize case) before calling Set.
  4. Extend the matchers if a new unit (e.g. KiB) is genuinely needed, adding a case that multiplies by the right factor.

Example fix

// before
size.Set("10GiB") // invalid _len "10GiB"
// after
size.Set("10GB") // matches the GB suffix matcher
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`(?i)^\d+\s*(b|kb|mb|gb|tb)$`)
if !re.MatchString(input) {
	return fmt.Errorf("unsupported size %q; use e.g. 10KB", input)
}

Try / catch

var siz size.Size
if err := siz.Set(userValue); err != nil {
	return fmt.Errorf("invalid size %q: %w", userValue, err)
}

Prevention

When it happens

Trigger: Calling Size.Set (or a parser that delegates to it, like TestParseDataUnit exercises) with a string whose unit suffix is unknown, misspelled, or missing — e.g. '10kib', '5 GIG', '10', '10XB'.

Common situations: Reading sizes from config files/env vars where users write '10GiB' or '10 Mb' while the parser only accepts its specific suffix set; missing unit entirely; lowercase/uppercase mismatch if matchers are case-sensitive; test fixtures using unsupported units.

Related errors


AI-assisted analysis of probelabs/goreplay@251e45abd2 (2026-09-02). Data as JSON: /api/errors/2fa246cfe9e14a5b. Report an issue: GitHub.