{"record":{"id":"b97687393203caa0","repo":"benbjohnson/litestream","slug":"create-table-s-w","errorCode":null,"errorMessage":"create table %s: %w","messagePattern":"create table (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":107,"sourceCode":"\t\treturn fmt.Errorf(\"set synchronous: %w\", err)\n\t}\n\n\tfor i := 0; i < c.TableCount; i++ {\n\t\ttableName := fmt.Sprintf(\"test_table_%d\", i)\n\n\t\tcreateSQL := fmt.Sprintf(`\n\t\t\tCREATE TABLE %s (\n\t\t\t\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\t\t\t\tdata BLOB,\n\t\t\t\ttext_field TEXT,\n\t\t\t\tint_field INTEGER,\n\t\t\t\tfloat_field REAL,\n\t\t\t\ttimestamp INTEGER\n\t\t\t)\n\t\t`, tableName)\n\n\t\tif _, err := db.Exec(createSQL); err != nil {\n\t\t\treturn fmt.Errorf(\"create table %s: %w\", tableName, err)\n\t\t}\n\n\t\tif c.IndexRatio > 0 {\n\t\t\tif rand.Float64() < c.IndexRatio {\n\t\t\t\tindexSQL := fmt.Sprintf(\"CREATE INDEX idx_%s_timestamp ON %s(timestamp)\", tableName, tableName)\n\t\t\t\tif _, err := db.Exec(indexSQL); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"create index: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif rand.Float64() < c.IndexRatio {\n\t\t\t\tindexSQL := fmt.Sprintf(\"CREATE INDEX idx_%s_int ON %s(int_field)\", tableName, tableName)\n\t\t\t\tif _, err := db.Exec(indexSQL); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"create index: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L89-L125","documentation":"populateDatabase wraps a failed CREATE TABLE for test_table_%d in this error. Each configured table is created with a fixed schema (data blob, text, int, float, timestamp columns) before rows are inserted. A failure means schema setup failed and no population for that table can proceed.","triggerScenarios":"db.Exec(createSQL) fails: a table with the same name already exists with a different schema, SQL syntax issues from a malformed table name, disk I/O error, or the database is read-only.","commonSituations":"Re-running populate against a database from a previous run without dropping tables; TableCount names colliding with pre-existing objects; disk full on the volume hosting the database.","solutions":["Drop existing test_table_* tables (or delete the database file) before re-running populate.","Check free disk space on the database volume.","Verify the wrapped SQLite error for 'table already exists' vs I/O errors.","Ensure the database file is not opened read-only."],"exampleFix":"// before\nlitestream-test populate -db data.db   // re-run, tables exist\n// after\nrm data.db data.db-wal data.db-shm && litestream-test populate -db data.db","handlingStrategy":"validation","validationCode":"var exists int\nif err := db.QueryRow(\"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?\", tableName).Scan(&exists); err != nil {\n    return err\n}\nif exists > 0 {\n    if _, err := db.Exec(fmt.Sprintf(\"DROP TABLE %s\", tableName)); err != nil {\n        return err\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := db.Exec(createSQL); err != nil {\n    if strings.Contains(err.Error(), \"already exists\") {\n        // drop and retry or skip\n    }\n    return fmt.Errorf(\"create table %s: %w\", tableName, err)\n}","preventionTips":["Delete the database file (plus -wal/-shm) before re-running populate.","Check sqlite_master for existing test tables before creating.","Monitor disk space before large schema operations.","Never open the test database read-only."],"tags":["sqlite","ddl","database"],"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"}