benbjohnson/litestream · error
delete percentage must be between 0 and 100
Error message
delete percentage must be between 0 and 100
What it means
The shrink command validates that the -delete-percentage flag falls within the inclusive range 0–100. A value outside that range is rejected before any database is touched. This guards against nonsensical deletion fractions that would either delete nothing meaningful or produce out-of-range row counts.
Source
Thrown at cmd/litestream-test/shrink.go:42
func (c *ShrinkCommand) Run(ctx context.Context, args []string) error {
fs := flag.NewFlagSet("litestream-test shrink", flag.ExitOnError)
fs.StringVar(&c.DB, "db", "", "Database path (required)")
fs.Float64Var(&c.DeletePercentage, "delete-percentage", 50, "Percentage of data to delete (0-100)")
fs.BoolVar(&c.Vacuum, "vacuum", false, "Run VACUUM after deletion")
fs.BoolVar(&c.Checkpoint, "checkpoint", false, "Run checkpoint after deletion")
fs.StringVar(&c.CheckpointMode, "checkpoint-mode", "PASSIVE", "Checkpoint mode (PASSIVE, FULL, RESTART, TRUNCATE)")
fs.Usage = c.Usage
if err := fs.Parse(args); err != nil {
return err
}
if c.DB == "" {
return fmt.Errorf("database path required")
}
if c.DeletePercentage < 0 || c.DeletePercentage > 100 {
return fmt.Errorf("delete percentage must be between 0 and 100")
}
if _, err := os.Stat(c.DB); err != nil {
return fmt.Errorf("database does not exist: %w", err)
}
slog.Info("Starting database shrink operation",
"db", c.DB,
"delete_percentage", c.DeletePercentage,
"vacuum", c.Vacuum,
"checkpoint", c.Checkpoint,
)
return c.shrinkDatabase(ctx)
}
func (c *ShrinkCommand) shrinkDatabase(ctx context.Context) error {
initialSize, err := getDatabaseSize(c.DB)View on GitHub (pinned to 4ed7a308f6)
Solutions
- Pass a percentage between 0 and 100, e.g. -delete-percentage 50
- If you meant 50%, use 50 not 0.5 (the flag expects a percentage, not a fraction)
- Verify the computed value in any calling script is clamped to [0, 100] before invoking
Example fix
// before litestream-test shrink -db test.db -delete-percentage 0.5 // after litestream-test shrink -db test.db -delete-percentage 50
Defensive patterns
Strategy: validation
Validate before calling
pct := 50.0 // compute as needed
if pct < 0 || pct > 100 {
return fmt.Errorf("delete percentage %v out of range [0,100]", pct)
} Prevention
- Remember the flag is a percentage (0-100), not a fraction (0-1)
- Clamp or validate computed percentages before passing them on the command line
- Quote negative values with = syntax (-delete-percentage=-5) so flag parsing doesn't treat them as flags
When it happens
Trigger: Invoking `litestream-test shrink` with a -delete-percentage value that is negative or greater than 100, e.g. -delete-percentage 150 or -delete-percentage -5; also triggered by a script passing a malformed computed percentage.
Common situations: Users misread the flag as a fraction (passing 1.5 intending 150% of nothing, or 0.5 meaning 50%); automation computes the percentage with an off-by-one or wrong unit; typo in the value like 05 instead of 50.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- invalid -timestamp, must specify in ISO 8601 format (e.g. 20
- database path required
- database path required
- source database path required
- replica URL or config file required
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/5d9bd7f7c736593f.
Report an issue: GitHub.