Tencent/WeKnora · error

failed to get row count: %w

Error message

failed to get row count: %w

What it means

LoadFromTable fails to obtain the table's row count while loading table-structured data for analysis; the COUNT(*) query executed against the analysis database returned an error (connection failure, permissions, or the quoted table name being invalid), aborting the load before schema info can be returned.

Source

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

		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,
		},
	}

	logger.Infof(ctx, "[Tool][DataAnalysis] Retrieved schema for table '%s' in session %s: %d columns, %d rows",
		tableName, t.sessionID, len(columns), rowCount)

	return schema, nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the analysis database connection is alive and the table exists
  2. Check that the table name is properly quoted/escaped and not injection-prone
  3. Confirm the querying role has SELECT permission on the table
  4. Make row count optional so schema info can still be returned if COUNT(*) fails
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/agent/tools/data_analysis.go:748 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/b75a8035bde0d93d. Report an issue: GitHub.