googleapis/mcp-toolbox · error
error iterating rows: %w
Error message
error iterating rows: %w
What it means
sqlite RunSQL (internal/sources/sqlite/sqlite.go:158) checks rows.Err() after the iteration loop completes. A non-nil error means the row iteration itself failed partway (driver/connection error mid-stream), not that all rows were read successfully. The error is wrapped as "error iterating rows" and returned instead of the partial results.
Source
Thrown at internal/sources/sqlite/sqlite.go:158
row.Add(name, nil)
continue
}
// Handle JSON data
if jsonString, ok := val.(string); ok {
var unmarshaledData any
if json.Unmarshal([]byte(jsonString), &unmarshaledData) == nil {
row.Add(name, unmarshaledData)
continue
}
}
// Store the value in the map
row.Add(name, val)
}
out = append(out, row)
}
if err = rows.Err(); err != nil {
return nil, fmt.Errorf("error iterating rows: %w", err)
}
return out, nil
}
func initSQLiteConnection(ctx context.Context, tracer trace.Tracer, name, dbPath string) (*sql.DB, error) {
//nolint:all // Reassigned ctx
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
// Open database connection
db, err := sql.Open("sqlite", dbPath)
if err != nil {
return nil, fmt.Errorf("sql.Open: %w", err)
}
// Set some reasonable defaults for SQLite
db.SetMaxOpenConns(1) // SQLite only supports one writer at a timeView on GitHub (pinned to 8cc6e09de2)
Solutions
- Read the wrapped driver error to identify the underlying I/O or OOM condition
- Reduce result set size with LIMIT or tighter WHERE clauses
- Extend the context timeout if deadlines fire during large scans
- Verify database file integrity and disk health (PRAGMA integrity_check, dmesg for I/O errors)
Defensive patterns
Strategy: retry
Try / catch
res, err := source.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "error iterating rows") {
// fail fast, alert on disk/IO health, optionally retry with LIMIT-reduced query
return fmt.Errorf("sqlite iteration failed: %w", err)
} Prevention
- Bound result sizes with LIMIT in tool SQL
- Monitor disk health and free space on the sqlite host
- Set adequate context timeouts for large scans
When it happens
Trigger: RunSQL where rows.Err() is non-nil after the for rows.Next() loop: an I/O error reading from the database file mid-iteration, out-of-memory in the driver, or context cancellation while fetching rows.
Common situations: Database file removed or corrupted while a query streams; disk I/O errors; very large result sets hitting memory limits; context deadline expiring during iteration.
Related errors
- unable to read config file at %q: %w
- unable to access config folder at %q: %w
- failed to read Google tokeninfo response: %w
- failed to read object %q in bucket %q: %w
- failed to read response body: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/009b55713bf4cb73.
Report an issue: GitHub.