{"record":{"id":"a4698fb9081b639d","repo":"benbjohnson/litestream","slug":"database-does-not-exist-w-a4698f","errorCode":null,"errorMessage":"database does not exist: %w","messagePattern":"database does not exist: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":46,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get initial size: %w\", err)\n\t}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L28-L64","documentation":"After flag validation, the shrink command calls os.Stat on the -db path. If the file cannot be stat'ed — typically because it does not exist — the error is wrapped as `database does not exist: %w`. The command operates on an existing SQLite database and never creates one, so a missing file is fatal.","triggerScenarios":"Passing -db with a path that does not exist, a typo'd filename, a relative path resolved from the wrong working directory, or a path where a permission error makes os.Stat fail (which also wraps here).","commonSituations":"Running the tool before the load-test generator created the database; pointing at a replica copy that was deleted; using an absolute path on a different machine/container where the file was never provisioned; symlink pointing to a removed target.","solutions":["Verify the path with ls -l <path> and correct any typo","Create the database first (e.g. run the load_test tool) before shrinking","Check you are running from the expected working directory if using a relative path","Check directory permissions if the file exists but os.Stat fails"],"exampleFix":"// before\nlitestream-test shrink -db /tmp/test.db\n// stat: no such file\n// after\nls /tmp/*.db  # confirm the actual filename\nlitestream-test shrink -db /tmp/load_test.db","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(dbPath); err != nil || info.IsDir() {\n    return fmt.Errorf(\"database not available at %s\", dbPath)\n}","typeGuard":null,"tryCatchPattern":"if err := runShrink(args); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Printf(\"database path problem: %v\", perr)\n    }\n    return err\n}","preventionTips":["Confirm the database exists with ls before running the tool","Use absolute paths in scripts to avoid working-directory surprises","Generate/load the test database before attempting to shrink it"],"tags":["cli","filesystem","sqlite","file-not-found"],"backgroundTag":"file-not-found","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"}