{"record":{"id":"ebfcb03296e1ace2","repo":"benbjohnson/litestream","slug":"database-does-not-exist-w","errorCode":null,"errorMessage":"database does not exist: %w","messagePattern":"database does not exist: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/load.go","lineNumber":61,"sourceCode":"\tfs := flag.NewFlagSet(\"litestream-test load\", flag.ExitOnError)\n\tfs.StringVar(&c.DB, \"db\", \"\", \"Database path (required)\")\n\tfs.IntVar(&c.WriteRate, \"write-rate\", 100, \"Writes per second\")\n\tfs.DurationVar(&c.Duration, \"duration\", 1*time.Minute, \"How long to run\")\n\tfs.StringVar(&c.Pattern, \"pattern\", \"constant\", \"Write pattern (constant, burst, random, wave)\")\n\tfs.IntVar(&c.PayloadSize, \"payload-size\", 1024, \"Size of each write operation in bytes\")\n\tfs.Float64Var(&c.ReadRatio, \"read-ratio\", 0.2, \"Read/write ratio (0.0-1.0)\")\n\tfs.IntVar(&c.Workers, \"workers\", 1, \"Number of concurrent workers\")\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 _, 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 load generation\",\n\t\t\"db\", c.DB,\n\t\t\"write_rate\", c.WriteRate,\n\t\t\"duration\", c.Duration,\n\t\t\"pattern\", c.Pattern,\n\t\t\"payload_size\", c.PayloadSize,\n\t\t\"read_ratio\", c.ReadRatio,\n\t\t\"workers\", c.Workers,\n\t)\n\n\treturn c.generateLoad(ctx)\n}\n\nfunc (c *LoadCommand) generateLoad(ctx context.Context) error {\n\tdb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")\n\tif err != nil {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/load.go#L43-L79","documentation":"The `litestream-test load` command verifies with os.Stat that the database file given via -db exists before starting load generation. If the stat call fails (file missing, path wrong, or permission issue on a path component), it wraps the underlying error in \"database does not exist\". This is an upfront precondition check so the tool fails fast instead of mid-run.","triggerScenarios":"Running `litestream-test load -db <path>` where the path does not exist on disk (typo, file deleted, relative path resolved from the wrong working directory, or a non-SQLite file that was never created by populate).","commonSituations":"Pointing -db at a database you forgot to create with `litestream-test populate` first; typos in the path; running from a different working directory than expected; expecting `load` to create the database (it does not — only populate does).","solutions":["Create the database first with `litestream-test populate -db <path>` or verify the file exists (ls <path>).","Check the path for typos and confirm you are running from the intended working directory (use an absolute path).","If the underlying error is a permission error rather than ENOENT, fix filesystem permissions on the path or its parent directories."],"exampleFix":"// before\nlitestream-test load -db ./data/test.db\n// error: database does not exist\n\n// after\nlitestream-test populate -db ./data/test.db   # creates the DB\nlitestream-test load -db ./data/test.db","handlingStrategy":"validation","validationCode":"const path = \"/path/to/test.db\";\nimport { existsSync, statSync } from \"fs\";\nif (!existsSync(path)) {\n  throw new Error(`database does not exist: ${path}; run 'litestream-test populate -db ${path}' first`);\n}\nif (!statSync(path).isFile()) {\n  throw new Error(`-db must be a file, got: ${path}`);\n}","typeGuard":"function dbFileExists(path) {\n  try { return statSync(path).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  await run(\"litestream-test\", [\"load\", \"-db\", dbPath]);\n} catch (e) {\n  if (String(e).includes(\"database does not exist\")) {\n    await run(\"litestream-test\", [\"populate\", \"-db\", dbPath]);\n    await run(\"litestream-test\", [\"load\", \"-db\", dbPath]);\n  } else throw e;\n}","preventionTips":["Always run `litestream-test populate` before `load` on a fresh path.","Use absolute paths in scripts to avoid cwd surprises.","Verify the file exists with ls/stat before launching long load runs."],"tags":["cli","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-14T05:17:10.506Z"}