{"record":{"id":"61f7db989fb0fd8c","repo":"benbjohnson/litestream","slug":"database-path-required-61f7db","errorCode":null,"errorMessage":"database path required","messagePattern":"database path required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":38,"sourceCode":"\tVacuum           bool\n\tCheckpoint       bool\n\tCheckpointMode   string\n}\n\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)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L20-L56","documentation":"The `litestream-test shrink` command aborts before doing any work because the required `-db` flag was not supplied (ShrinkCommand.DB is the empty string). The Run method validates flag input immediately after flag parsing and refuses to proceed without a database path. This is a pure user-input validation error, not a library or environment failure.","triggerScenarios":"Running `litestream-test shrink` without the `-db PATH` flag, or invoking ShrinkCommand.Run programmatically with args that omit `-db`, leaving c.DB empty after flag.Parse.","commonSituations":"Developers copy a sample command line and drop the -db flag; scripts interpolate an empty DB path variable (e.g. DB_PATH unset); users pass the path as a positional argument instead of a flag, which Go's flag package ignores.","solutions":["Run the command with the required flag: litestream-test shrink -db /path/to/test.db","If a shell script calls it, verify the path variable is non-empty before invoking the command","Check `litestream-test shrink` usage output for the exact -db syntax"],"exampleFix":"// before\nlitestream-test shrink -delete-percentage 50\n// after\nlitestream-test shrink -db /tmp/test.db -delete-percentage 50","handlingStrategy":"validation","validationCode":"if dbPath == \"\" {\n    return fmt.Errorf(\"-db flag is required\")\n}\n// then run:\n// litestream-test shrink -db /path/to/test.db ...","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass -db explicitly; never rely on defaults for required flags","In scripts, assert the path variable is non-empty: [ -n \"$DB_PATH\" ] || exit 1","Remember Go's flag package ignores positional args — the path must follow -db"],"tags":["cli","validation","sqlite"],"backgroundTag":"missing-required-flag","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}