benbjohnson/litestream · error
database does not exist: %w
Error message
database does not exist: %w
What it means
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.
Source
Thrown at cmd/litestream-test/shrink.go:46
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)
if err != nil {
return fmt.Errorf("get initial size: %w", err)
}
View on GitHub (pinned to 4ed7a308f6)
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
Example fix
// before litestream-test shrink -db /tmp/test.db // stat: no such file // after ls /tmp/*.db # confirm the actual filename litestream-test shrink -db /tmp/load_test.db
Defensive patterns
Strategy: validation
Validate before calling
if info, err := os.Stat(dbPath); err != nil || info.IsDir() {
return fmt.Errorf("database not available at %s", dbPath)
} Try / catch
if err := runShrink(args); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) {
log.Printf("database path problem: %v", perr)
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- database does not exist: %w
- open database: %w
- ensure test table: %w
- populate database: %w
- open database: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/a4698fb9081b639d.
Report an issue: GitHub.