benbjohnson/litestream · error

insert row: %w

Error message

insert row: %w

What it means

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).

Source

Thrown at cmd/litestream-test/populate.go:204

			return fmt.Errorf("prepare statement: %w", err)
		}

		batchEnd := i + c.BatchSize
		if batchEnd > rowCount {
			batchEnd = rowCount
		}

		for j := i; j < batchEnd; j++ {
			cryptorand.Read(data)
			textField := fmt.Sprintf("row_%d_%d", i, j)
			intField := rand.Int63()
			floatField := rand.Float64() * 1000
			timestamp := time.Now().Unix()

			if _, err := stmt.Exec(data, textField, intField, floatField, timestamp); err != nil {
				stmt.Close()
				tx.Rollback()
				return fmt.Errorf("insert row: %w", err)
			}
		}

		stmt.Close()
		if err := tx.Commit(); err != nil {
			return fmt.Errorf("commit transaction: %w", err)
		}

		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}
	}

	return nil
}

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check disk space; SQLITE_FULL during bulk inserts is the most common cause.
  2. Lower -target-bytes or row size so the final database fits the volume.
  3. Ensure no concurrent process modifies the test tables during the run.
  4. Inspect the wrapped error for the specific SQLite result code.

Example fix

// before
litestream-test populate -db data.db -target-bytes 100000000000   // 100GB, disk has 10GB
// after
litestream-test populate -db data.db -target-bytes 5000000000     // fits available space
Defensive patterns

Strategy: validation

Validate before calling

// preflight disk space check sized for the target database
var st syscall.Statfs_t
if err := syscall.Statfs(filepath.Dir(c.DB), &st); err == nil {
    avail := int64(st.Bavail) * int64(st.Bsize)
    if avail < targetBytes*2 { // db + WAL headroom
        return fmt.Errorf("insufficient disk: need ~%d, have %d", targetBytes*2, avail)
    }
}

Try / catch

if _, err := stmt.Exec(data, textField, intField, floatField, timestamp); err != nil {
    stmt.Close()
    tx.Rollback()
    if strings.Contains(err.Error(), "SQLITE_FULL") {
        return fmt.Errorf("insert row: disk full: %w", err)
    }
    return fmt.Errorf("insert row: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


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