benbjohnson/litestream · error
invalid target size: %w
Error message
invalid target size: %w
What it means
populate parses the -target-size flag (default "100MB") with parseSize, which expects a size string like "1GB", "500MB". If the string cannot be parsed into a byte count, Run wraps the parse error as "invalid target size". This validates user-supplied size notation before any database work starts.
Source
Thrown at cmd/litestream-test/populate.go:49
fs.StringVar(&c.DB, "db", "", "Database path (required)")
fs.StringVar(&c.TargetSize, "target-size", "100MB", "Target database size (e.g., 1GB, 500MB)")
fs.IntVar(&c.RowSize, "row-size", 1024, "Average row size in bytes")
fs.IntVar(&c.BatchSize, "batch-size", 1000, "Rows per transaction")
fs.IntVar(&c.TableCount, "table-count", 1, "Number of tables to create")
fs.Float64Var(&c.IndexRatio, "index-ratio", 0.2, "Percentage of columns to index (0.0-1.0)")
fs.IntVar(&c.PageSize, "page-size", 4096, "SQLite page size in bytes")
fs.Usage = c.Usage
if err := fs.Parse(args); err != nil {
return err
}
if c.DB == "" {
return fmt.Errorf("database path required")
}
targetBytes, err := parseSize(c.TargetSize)
if err != nil {
return fmt.Errorf("invalid target size: %w", err)
}
slog.Info("Starting database population",
"db", c.DB,
"target_size", c.TargetSize,
"row_size", c.RowSize,
"batch_size", c.BatchSize,
"table_count", c.TableCount,
"page_size", c.PageSize,
)
if err := c.populateDatabase(ctx, targetBytes); err != nil {
return fmt.Errorf("populate database: %w", err)
}
slog.Info("Database population complete", "db", c.DB)
return nil
}View on GitHub (pinned to 4ed7a308f6)
Solutions
- Use a plain value with a supported unit suffix, e.g. `-target-size 1GB` or `-target-size 500MB` (match the format shown in the flag help).
- Remove thousands separators, spaces, or non-standard suffixes (GiB/KiB) from the value.
- Check the parseSize implementation in this repo for the exact accepted units and case sensitivity if unsure.
Example fix
// before litestream-test populate -db ./test.db -target-size 1GiB // error: invalid target size // after litestream-test populate -db ./test.db -target-size 1GB
Defensive patterns
Strategy: validation
Validate before calling
const m = /^\d+(KB|MB|GB)$/.exec(targetSize);
if (!m) throw new Error(`invalid target size "${targetSize}": use forms like 100MB or 1GB`); Type guard
function isValidSize(s) {
return /^\d+(KB|MB|GB)$/.test(s);
} Try / catch
try {
await run("litestream-test", ["populate", "-db", dbPath, "-target-size", targetSize]);
} catch (e) {
if (String(e).includes("invalid target size")) {
console.error(`"${targetSize}" is not parseable; use <number><KB|MB|GB>, e.g. 500MB`);
}
throw e;
} Prevention
- Use unit suffixes exactly as documented (KB/MB/GB), no spaces or GiB-style suffixes.
- Avoid locale-formatted numbers (commas, decimal commas) in size strings.
- Quote the whole -target-size value in shell to prevent splitting.
When it happens
Trigger: Passing `-target-size` values parseSize cannot handle: plain numbers without a unit suffix, misspelled units ("1gb" if case-sensitive, "1 GiB", "1G B"), negative values, or empty strings.
Common situations: Users writing "1GiB" or "1 Gb" instead of the accepted format; locale-formatted numbers ("1,5GB"); shell quoting issues splitting the value from the flag.
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
- flag %q must be positioned before DB_PATH and REPLICA_URL ar
- config file not found
- invalid -timestamp, must specify in ISO 8601 format (e.g. 20
- database path required
- database does not exist: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/7427ec71ab09df9f.
Report an issue: GitHub.