{"record":{"id":"522bd87328639f66","repo":"benbjohnson/litestream","slug":"insert-row-w","errorCode":null,"errorMessage":"insert row: %w","messagePattern":"insert row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":204,"sourceCode":"\t\t\treturn fmt.Errorf(\"prepare statement: %w\", err)\n\t\t}\n\n\t\tbatchEnd := i + c.BatchSize\n\t\tif batchEnd > rowCount {\n\t\t\tbatchEnd = rowCount\n\t\t}\n\n\t\tfor j := i; j < batchEnd; j++ {\n\t\t\tcryptorand.Read(data)\n\t\t\ttextField := fmt.Sprintf(\"row_%d_%d\", i, j)\n\t\t\tintField := rand.Int63()\n\t\t\tfloatField := rand.Float64() * 1000\n\t\t\ttimestamp := time.Now().Unix()\n\n\t\t\tif _, err := stmt.Exec(data, textField, intField, floatField, timestamp); err != nil {\n\t\t\t\tstmt.Close()\n\t\t\t\ttx.Rollback()\n\t\t\t\treturn fmt.Errorf(\"insert row: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tstmt.Close()\n\t\tif err := tx.Commit(); err != nil {\n\t\t\treturn fmt.Errorf(\"commit transaction: %w\", err)\n\t\t}\n\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L186-L222","documentation":"populateTable wraps a failed stmt.Exec for an individual row in this error. Each row inside the batch transaction executes this INSERT with generated blob, text, integer, float and timestamp values. On failure the statement is closed and the transaction rolled back, aborting the whole batch (and via the caller, the run).","triggerScenarios":"stmt.Exec(...) fails: disk full (SQLITE_FULL) mid-batch, the table was dropped/altered concurrently, a constraint or datatype rejection, or the connection was lost mid-transaction.","commonSituations":"Large target sizes exhausting disk space during population; another process dropping or rewriting test tables; row data exceeding limits (e.g. RowSize beyond SQLite's max blob handling in the driver).","solutions":["Check disk space; SQLITE_FULL during bulk inserts is the most common cause.","Lower -target-bytes or row size so the final database fits the volume.","Ensure no concurrent process modifies the test tables during the run.","Inspect the wrapped error for the specific SQLite result code."],"exampleFix":"// before\nlitestream-test populate -db data.db -target-bytes 100000000000   // 100GB, disk has 10GB\n// after\nlitestream-test populate -db data.db -target-bytes 5000000000     // fits available space","handlingStrategy":"validation","validationCode":"// preflight disk space check sized for the target database\nvar st syscall.Statfs_t\nif err := syscall.Statfs(filepath.Dir(c.DB), &st); err == nil {\n    avail := int64(st.Bavail) * int64(st.Bsize)\n    if avail < targetBytes*2 { // db + WAL headroom\n        return fmt.Errorf(\"insufficient disk: need ~%d, have %d\", targetBytes*2, avail)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := stmt.Exec(data, textField, intField, floatField, timestamp); err != nil {\n    stmt.Close()\n    tx.Rollback()\n    if strings.Contains(err.Error(), \"SQLITE_FULL\") {\n        return fmt.Errorf(\"insert row: disk full: %w\", err)\n    }\n    return fmt.Errorf(\"insert row: %w\", err)\n}","preventionTips":["Keep target size well under available disk (allow WAL headroom).","Don't mutate test tables from other processes mid-run.","Keep RowSize within driver/SQLite blob limits.","Roll back and close the statement on the first insert error, as the code does."],"tags":["sqlite","insert","bulk-insert"],"backgroundTag":"database-write-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"}