Tencent/WeKnora · error

error iterating schema rows: %w

Error message

error iterating schema rows: %w

What it means

Iteration wrapper in LoadFromTable: after scanning all available rows, rows.Err() reported a driver-level failure during iteration over the schema/metadata query (connection drop, cancelled context, driver error). The loaded column list is abandoned and the whole table load fails with the cause wrapped.

Source

Thrown at internal/agent/tools/data_analysis.go:740

		if err != nil {
			// Try with fewer columns
			err = rows.Scan(&colName, &colType, &nullable)
			if err != nil {
				logger.Errorf(ctx, "[Tool][DataAnalysis] Failed to scan column info: %v", err)
				return nil, fmt.Errorf("failed to scan column info: %w", err)
			}
		}

		columns = append(columns, ColumnInfo{
			Name:     colName,
			Type:     colType,
			Nullable: nullable,
		})
	}

	if err := rows.Err(); err != nil {
		logger.Errorf(ctx, "[Tool][DataAnalysis] Error iterating schema rows: %v", err)
		return nil, fmt.Errorf("error iterating schema rows: %w", err)
	}

	// Get row count
	countSQL := fmt.Sprintf("SELECT COUNT(*) FROM \"%s\"", tableName)
	var rowCount int64
	if err := t.db.QueryRowContext(ctx, countSQL).Scan(&rowCount); err != nil {
		logger.Errorf(ctx, "[Tool][DataAnalysis] Failed to get row count: %v", err)
		return nil, fmt.Errorf("failed to get row count: %w", err)
	}

	schema := &TableSchema{
		TableName: tableName,
		Columns:   columns,
		RowCount:  rowCount,
		Metadata: map[string]interface{}{
			"column_count": len(columns),
			"session_id":   t.sessionID,
		},

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the wrapped driver error; reconnect if the DB connection was lost
  2. Retry the table load, checking for context cancellation/timeout
  3. Reduce query scope or fix driver issues if large schema iterations fail repeatedly
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/agent/tools/data_analysis.go:740 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/d72f8ab5ccba6563. Report an issue: GitHub.