benbjohnson/litestream · error
invalid size format: %w
Error message
invalid size format: %w
What it means
ParseByteSize failed because github.com/dustin/go-humanize could not interpret the string as a byte size. The underlying humanize error is chained, indicating unsupported units or non-numeric characters.
Source
Thrown at cmd/litestream/main.go:1100
return err
}
*b = ByteSize(size)
return nil
}
// ParseByteSize parses a byte size string using github.com/dustin/go-humanize.
// Supports both SI units (KB=1000, MB=1000², etc.) and IEC units (KiB=1024, MiB=1024², etc.).
// Examples: "1MB", "5MiB", "1.5GB", "100B", "1024KB"
func ParseByteSize(s string) (int64, error) {
s = strings.TrimSpace(s)
if s == "" {
return 0, fmt.Errorf("empty size string")
}
// Use go-humanize to parse the byte size string
bytes, err := humanize.ParseBytes(s)
if err != nil {
return 0, fmt.Errorf("invalid size format: %w", err)
}
// Check that the value fits in int64
if bytes > math.MaxInt64 {
return 0, fmt.Errorf("size %d exceeds maximum allowed value (%d)", bytes, int64(math.MaxInt64))
}
return int64(bytes), nil
}
// ReplicaSettings contains settings shared across replica configurations.
// These can be set globally in Config or per-replica in ReplicaConfig.
type ReplicaSettings struct {
SyncInterval *time.Duration `yaml:"sync-interval"`
ValidationInterval *time.Duration `yaml:"validation-interval"`
// Maximum L0 files to upload in a single monitor sync run.
// Set to zero to process all pending L0 files in one run.View on GitHub (pinned to 4ed7a308f6)
Solutions
- Use supported forms: "1MB", "5MiB", "1.5GB", "100B", "1024KB"
- Remove thousands separators and stray characters from the value
- Check the chained humanize error text for the offending character
Example fix
# before max-size: 1,5GB # after max-size: 1.5GB
Defensive patterns
Strategy: validation
Validate before calling
if _, err := humanize.ParseBytes(cfg.Size); err != nil {
return fmt.Errorf("size %q not parseable: use forms like 1MB, 5MiB, 1.5GB", cfg.Size)
} Prevention
- Stick to documented size spellings (MB/MiB/GB/KB/B)
- Avoid locale number formatting (no comma separators)
- Add a config lint step that runs ParseByteSize on all size fields
When it happens
Trigger: Config size values like "1 gb" with unsupported spelling, "10 bytes" , "1,5GB", "abc", or trailing characters such as "5MB!" passed to a size config field.
Common situations: Typos in unit suffixes (e.g. "5mB" vs "5MB"), locale-formatted numbers with commas, users writing durations where sizes are expected.
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
- parse replica url: %w
- empty size string
- size %d exceeds maximum allowed value (%d)
- cannot parse exec command: %w
- heartbeat URL must be a valid HTTP or HTTPS URL
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/13758e8f69c5de05.
Report an issue: GitHub.