{"record":{"id":"5d9bd7f7c736593f","repo":"benbjohnson/litestream","slug":"delete-percentage-must-be-between-0-and-100","errorCode":null,"errorMessage":"delete percentage must be between 0 and 100","messagePattern":"delete percentage must be between 0 and 100","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":42,"sourceCode":"\nfunc (c *ShrinkCommand) Run(ctx context.Context, args []string) error {\n\tfs := flag.NewFlagSet(\"litestream-test shrink\", flag.ExitOnError)\n\tfs.StringVar(&c.DB, \"db\", \"\", \"Database path (required)\")\n\tfs.Float64Var(&c.DeletePercentage, \"delete-percentage\", 50, \"Percentage of data to delete (0-100)\")\n\tfs.BoolVar(&c.Vacuum, \"vacuum\", false, \"Run VACUUM after deletion\")\n\tfs.BoolVar(&c.Checkpoint, \"checkpoint\", false, \"Run checkpoint after deletion\")\n\tfs.StringVar(&c.CheckpointMode, \"checkpoint-mode\", \"PASSIVE\", \"Checkpoint mode (PASSIVE, FULL, RESTART, TRUNCATE)\")\n\tfs.Usage = c.Usage\n\tif err := fs.Parse(args); err != nil {\n\t\treturn err\n\t}\n\n\tif c.DB == \"\" {\n\t\treturn fmt.Errorf(\"database path required\")\n\t}\n\n\tif c.DeletePercentage < 0 || c.DeletePercentage > 100 {\n\t\treturn fmt.Errorf(\"delete percentage must be between 0 and 100\")\n\t}\n\n\tif _, err := os.Stat(c.DB); err != nil {\n\t\treturn fmt.Errorf(\"database does not exist: %w\", err)\n\t}\n\n\tslog.Info(\"Starting database shrink operation\",\n\t\t\"db\", c.DB,\n\t\t\"delete_percentage\", c.DeletePercentage,\n\t\t\"vacuum\", c.Vacuum,\n\t\t\"checkpoint\", c.Checkpoint,\n\t)\n\n\treturn c.shrinkDatabase(ctx)\n}\n\nfunc (c *ShrinkCommand) shrinkDatabase(ctx context.Context) error {\n\tinitialSize, err := getDatabaseSize(c.DB)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlitestream-test shrink -db test.db -delete-percentage 0.5\n// after\nlitestream-test shrink -db test.db -delete-percentage 50","handlingStrategy":"validation","validationCode":"pct := 50.0 // compute as needed\nif pct < 0 || pct > 100 {\n    return fmt.Errorf(\"delete percentage %v out of range [0,100]\", pct)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","validation","range-check"],"backgroundTag":"value-out-of-range","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}