{"record":{"id":"ea58a29804039b78","repo":"benbjohnson/litestream","slug":"create-table-w","errorCode":null,"errorMessage":"create table: %w","messagePattern":"create table: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/load.go","lineNumber":206,"sourceCode":"\t\treturn 4 * x * (3.14159265359 - x) / (3.14159265359 * 3.14159265359)\n\t}\n\tx = x - 3.14159265359\n\treturn -4 * x * (3.14159265359 - x) / (3.14159265359 * 3.14159265359)\n}\n\nfunc (c *LoadCommand) ensureTestTable(db *sql.DB) error {\n\tcreateSQL := `\n\t\tCREATE TABLE IF NOT EXISTS load_test (\n\t\t\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\t\t\tdata BLOB,\n\t\t\ttext_field TEXT,\n\t\t\tint_field INTEGER,\n\t\t\ttimestamp INTEGER\n\t\t)\n\t`\n\t_, err := db.Exec(createSQL)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create table: %w\", err)\n\t}\n\n\t_, err = db.Exec(\"CREATE INDEX IF NOT EXISTS idx_load_test_timestamp ON load_test(timestamp)\")\n\treturn err\n}\n\nfunc (c *LoadCommand) performWrite(db *sql.DB, data []byte) error {\n\ttextField := fmt.Sprintf(\"load_%d\", time.Now().UnixNano())\n\tintField := rand.Int63()\n\ttimestamp := time.Now().Unix()\n\n\t_, err := db.Exec(`\n\t\tINSERT INTO load_test (data, text_field, int_field, timestamp)\n\t\tVALUES (?, ?, ?, ?)\n\t`, data, textField, intField, timestamp)\n\n\treturn err\n}","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/load.go#L188-L224","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Confirm the file is a valid SQLite database; if not, remove/recreate it with `litestream-test populate`.","Ensure no other process holds a write lock (close other connections, wait for busy timeout).","Check free disk space and write permissions on the database directory.","Re-run; transient SQLITE_BUSY failures often clear once competing writers exit."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure no competing writer holds the DB before running\n// (check for -wal/-shm activity from other processes, and free disk space)\nimport { statSync } from \"fs\";\nstatSync(dbPath); // throws early if the file is missing/unreadable","typeGuard":null,"tryCatchPattern":"let lastErr;\nfor (let attempt = 1; attempt <= 3; attempt++) {\n  try { await run(\"litestream-test\", [\"load\", \"-db\", dbPath]); return; }\n  catch (e) {\n    lastErr = e;\n    if (!String(e).includes(\"create table\")) throw e; // only retry DDL failures\n    await sleep(1000 * attempt); // back off for SQLITE_BUSY-style transients\n  }\n}\nthrow lastErr;","preventionTips":["Ensure only one load/populate process writes to a given database at a time.","Monitor free disk space; DDL fails immediately when the disk is full.","Validate the target file is a SQLite database (\"SQLite format 3\" header) before running."],"tags":["sqlite","sql","ddl"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}