benbjohnson/litestream · error
invalid cache_size: %w
Error message
invalid cache_size: %w
What it means
Validation in the VFS URI config Set method: the cache_size parameter is not a valid integer. Fires when parsing a vfs:// URI whose cache_size query value cannot be parsed by strconv.Atoi (e.g. 'cache_size=big').
Source
Thrown at vfs_config.go:88
}
cfg.SyncInterval = &d
case "buffer_path":
cfg.BufferPath = value
case "hydration_enabled":
b := strings.ToLower(value) == "true" || value == "1"
cfg.HydrationEnabled = &b
case "hydration_path":
cfg.HydrationPath = value
case "poll_interval":
d, err := time.ParseDuration(value)
if err != nil {
return fmt.Errorf("invalid poll_interval: %w", err)
}
cfg.PollInterval = &d
case "cache_size":
n, err := strconv.Atoi(value)
if err != nil {
return fmt.Errorf("invalid cache_size: %w", err)
}
cfg.CacheSize = &n
default:
return fmt.Errorf("unknown config key: %s", key)
}
return nil
}
func ParseVFSURIConfig(uriParameters map[string]string) (*VFSConfig, error) {
if len(uriParameters) == 0 {
return nil, nil
}
cfg := &VFSConfig{}
var found bool
for _, key := range vfsURIConfigKeys {
value, ok := uriParameters[key]
if !ok {View on GitHub (pinned to 4ed7a308f6)
Solutions
- Provide a plain integer in bytes, e.g. cache_size=67108864
- Strip units/separators from the configured value and convert to bytes yourself
- Validate numeric params before building the VFS URI
Example fix
// before litestream://file:///db?cache_size=64MB // after litestream://file:///db?cache_size=67108864
Defensive patterns
Strategy: validation
Validate before calling
n, err := strconv.Atoi(v)
if err != nil { return fmt.Errorf("cache_size must be a plain integer (bytes): %w", err) }
_ = n Try / catch
if err := cfg.Set("cache_size", v); err != nil {
if strings.Contains(err.Error(), "invalid cache_size") {
// convert human sizes (e.g. 64MB) to bytes before retry
}
} Prevention
- Express cache sizes as raw byte integers in URI parameters
- Convert human-readable sizes to bytes in your own config layer
- Trim whitespace from templated config values
When it happens
Trigger: Calling Set("cache_size", <value>) — directly or via ParseVFSURIConfig — where strconv.Atoi fails, e.g. "64MB", "1_000", "" or "0x100".
Common situations: Writing cache_size=64MB in a URI (units not accepted); thousands separators; whitespace; templated config leaving the parameter blank.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- invalid sync_interval: %w
- invalid poll_interval: %w
- unknown config key: %s
- snapshot interval must be greater than 0
- snapshot retention must be greater than 0
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/d71d6a2ec827fc87.
Report an issue: GitHub.