benbjohnson/litestream · error
populate database: %w
Error message
populate database: %w
What it means
Run wraps any failure from populateDatabase as "populate database". populateDatabase opens the SQLite file, sets pragmas (page size, journal mode, synchronous), creates tables, and inserts rows until the target size is reached; any failure anywhere in that pipeline is surfaced with this wrapper, with the root cause preserved via %w.
Source
Thrown at cmd/litestream-test/populate.go:62
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)
}
slog.Info("Database population complete", "db", c.DB)
return nil
}
func (c *PopulateCommand) populateDatabase(ctx context.Context, targetBytes int64) error {
if err := os.Remove(c.DB); err != nil && !os.IsNotExist(err) {
slog.Warn("Could not remove existing database", "error", err)
}
db, err := sql.Open("sqlite3", c.DB)
if err != nil {
return fmt.Errorf("open database: %w", err)
}
defer db.Close()
if _, err := db.Exec(fmt.Sprintf("PRAGMA page_size = %d", c.PageSize)); err != nil {View on GitHub (pinned to 4ed7a308f6)
Solutions
- Read the wrapped inner error to identify the root cause (disk full vs SQL error vs busy).
- Free disk space or lower `-target-size` so the database can actually reach the requested size.
- Reduce contention: stop other processes writing to the same database, or lower `-batch-size`.
- Adjust `-row-size`/`-page-size` to compatible values if the inner error indicates a SQLite limit violation.
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: enough free space for the target size?
import { statfsSync } from "fs";
const need = parseSizeBytes(targetSize); // e.g. 1GB -> 1e9
const { bavail, bsize } = statfsSync(path.dirname(dbPath));
if (bavail * bsize < need * 1.2) throw new Error("insufficient free disk space for -target-size " + targetSize); Try / catch
try {
await run("litestream-test", ["populate", "-db", dbPath, "-target-size", targetSize]);
} catch (e) {
if (String(e).includes("populate database")) {
if (/disk I/O error|no space/i.test(String(e.cause ?? e))) {
console.error("Free disk space or lower -target-size, then retry.");
}
}
throw e;
} Prevention
- Check free disk space against the target size before populating.
- Lower -row-size/-batch-size if you hit SQLite limits mid-run.
- Avoid running other writers against the same DB during population.
When it happens
Trigger: Any mid-population failure: SQL execution errors during table creation or batch inserts, disk becoming full while growing the DB to the target size, context cancellation/timeout, or connection failures.
Common situations: Disk filling up before reaching a large -target-size (most common for multi-GB targets); SQLITE_BUSY from concurrent access; invalid combination of flags (e.g., row-size larger than allowed by page size constraints); interrupted transactions.
Related errors
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/6cfdda8a99e3d403.
Report an issue: GitHub.