benbjohnson/litestream · error

create table: %w

Error message

create table: %w

What it means

ensureTestTable executes the CREATE TABLE IF NOT EXISTS load_test statement via db.Exec and wraps any failure as "create table". This is a direct SQLite DDL execution error — the statement itself could not be completed against the database.

Source

Thrown at cmd/litestream-test/load.go:206

		return 4 * x * (3.14159265359 - x) / (3.14159265359 * 3.14159265359)
	}
	x = x - 3.14159265359
	return -4 * x * (3.14159265359 - x) / (3.14159265359 * 3.14159265359)
}

func (c *LoadCommand) ensureTestTable(db *sql.DB) error {
	createSQL := `
		CREATE TABLE IF NOT EXISTS load_test (
			id INTEGER PRIMARY KEY AUTOINCREMENT,
			data BLOB,
			text_field TEXT,
			int_field INTEGER,
			timestamp INTEGER
		)
	`
	_, err := db.Exec(createSQL)
	if err != nil {
		return fmt.Errorf("create table: %w", err)
	}

	_, err = db.Exec("CREATE INDEX IF NOT EXISTS idx_load_test_timestamp ON load_test(timestamp)")
	return err
}

func (c *LoadCommand) performWrite(db *sql.DB, data []byte) error {
	textField := fmt.Sprintf("load_%d", time.Now().UnixNano())
	intField := rand.Int63()
	timestamp := time.Now().Unix()

	_, err := db.Exec(`
		INSERT INTO load_test (data, text_field, int_field, timestamp)
		VALUES (?, ?, ?, ?)
	`, data, textField, intField, timestamp)

	return err
}

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Confirm the file is a valid SQLite database; if not, remove/recreate it with `litestream-test populate`.
  2. Ensure no other process holds a write lock (close other connections, wait for busy timeout).
  3. Check free disk space and write permissions on the database directory.
  4. Re-run; transient SQLITE_BUSY failures often clear once competing writers exit.
Defensive patterns

Strategy: retry

Validate before calling

// ensure no competing writer holds the DB before running
// (check for -wal/-shm activity from other processes, and free disk space)
import { statSync } from "fs";
statSync(dbPath); // throws early if the file is missing/unreadable

Try / catch

let lastErr;
for (let attempt = 1; attempt <= 3; attempt++) {
  try { await run("litestream-test", ["load", "-db", dbPath]); return; }
  catch (e) {
    lastErr = e;
    if (!String(e).includes("create table")) throw e; // only retry DDL failures
    await sleep(1000 * attempt); // back off for SQLITE_BUSY-style transients
  }
}
throw lastErr;

Prevention

When it happens

Trigger: `litestream-test load` against a database where the load_test DDL fails: the file is not a SQLite database ("file is not a database" error), disk is full, the DB is locked by another writer, or the connection is broken.

Common situations: Corrupted or wrong-format database file; another process (e.g., a previous load run or litestream itself) holds the write lock; read-only mount; SQLITE_BUSY under concurrent access.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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