benbjohnson/litestream · error

database path required

Error message

database path required

What it means

The `litestream-test populate` command requires a database path via the -db flag. After flag parsing, if c.DB is still the empty string, Run returns "database path required". The tool never infers a default path, so the flag must be supplied explicitly.

Source

Thrown at cmd/litestream-test/populate.go:44

	PageSize   int
}

func (c *PopulateCommand) Run(ctx context.Context, args []string) error {
	fs := flag.NewFlagSet("litestream-test populate", flag.ExitOnError)
	fs.StringVar(&c.DB, "db", "", "Database path (required)")
	fs.StringVar(&c.TargetSize, "target-size", "100MB", "Target database size (e.g., 1GB, 500MB)")
	fs.IntVar(&c.RowSize, "row-size", 1024, "Average row size in bytes")
	fs.IntVar(&c.BatchSize, "batch-size", 1000, "Rows per transaction")
	fs.IntVar(&c.TableCount, "table-count", 1, "Number of tables to create")
	fs.Float64Var(&c.IndexRatio, "index-ratio", 0.2, "Percentage of columns to index (0.0-1.0)")
	fs.IntVar(&c.PageSize, "page-size", 4096, "SQLite page size in bytes")
	fs.Usage = c.Usage
	if err := fs.Parse(args); err != nil {
		return err
	}

	if c.DB == "" {
		return fmt.Errorf("database path required")
	}

	targetBytes, err := parseSize(c.TargetSize)
	if err != nil {
		return fmt.Errorf("invalid target size: %w", err)
	}

	slog.Info("Starting database population",
		"db", c.DB,
		"target_size", c.TargetSize,
		"row_size", c.RowSize,
		"batch_size", c.BatchSize,
		"table_count", c.TableCount,
		"page_size", c.PageSize,
	)

	if err := c.populateDatabase(ctx, targetBytes); err != nil {
		return fmt.Errorf("populate database: %w", err)

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Pass the flag explicitly: `litestream-test populate -db /path/to/test.db`.
  2. In scripts, verify the path variable is non-empty before invoking the command (`: "${DB_PATH:?DB_PATH not set}"`).
  3. Run `litestream-test populate -h` to see the required flags.

Example fix

// before (script)
litestream-test populate -target-size 1GB
// error: database path required

// after (script)
: "${DB_PATH:?set DB_PATH}"
litestream-test populate -db "$DB_PATH" -target-size 1GB
Defensive patterns

Strategy: validation

Validate before calling

if (!dbPath || dbPath.trim() === "") {
  throw new Error("-db is required for litestream-test populate");
}

Type guard

function hasDbPath(args) {
  const i = args.indexOf("-db");
  return i !== -1 && typeof args[i + 1] === "string" && args[i + 1] !== "";
}

Try / catch

try {
  await run("litestream-test", ["populate", ...args]);
} catch (e) {
  if (String(e).includes("database path required")) {
    console.error("populate requires -db <path>; got args: " + args.join(" "));
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `litestream-test populate` without `-db <path>`, or passing `-db` with an empty value (`-db ""`).

Common situations: Forgetting the flag in scripts; a variable holding the path being empty/unset in shell scripts (e.g., $DB_PATH unset); assuming a default test database path exists.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/de4291099feb7a11. Report an issue: GitHub.