googleapis/mcp-toolbox · error

unable to parse row: %w

Error message

unable to parse row: %w

What it means

During row iteration, results.Scan(values...) failed for a particular row. RunSQL wraps it as 'unable to parse row', meaning a value in the result could not be scanned into the generic any placeholders, or type-conversion handling for the column type failed.

Source

Thrown at internal/sources/clickhouse/clickhouse.go:140

	}

	// create an array of values for each column, which can be re-used to scan each row
	rawValues := make([]any, len(cols))
	values := make([]any, len(cols))
	for i := range rawValues {
		values[i] = &rawValues[i]
	}

	colTypes, err := results.ColumnTypes()
	if err != nil {
		return nil, fmt.Errorf("unable to get column types: %w", err)
	}

	out := []any{}
	for results.Next() {
		err := results.Scan(values...)
		if err != nil {
			return nil, fmt.Errorf("unable to parse row: %w", err)
		}
		vMap := make(map[string]any)
		for i, name := range cols {
			// ClickHouse driver may return specific types that need handling
			switch colTypes[i].DatabaseTypeName() {
			case "String", "FixedString":
				if rawValues[i] != nil {
					// Handle potential []byte to string conversion if needed
					if b, ok := rawValues[i].([]byte); ok {
						vMap[name] = string(b)
					} else {
						vMap[name] = rawValues[i]
					}
				} else {
					vMap[name] = nil
				}
			default:
				vMap[name] = rawValues[i]

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Look at the wrapped scan error to find the offending column/type.
  2. Add handling for the column type in the DatabaseTypeName switch in RunSQL.
  3. Cast/COALESCE problematic columns in SQL (e.g. toString(col), toNullable(col)).
  4. Upgrade or pin the clickhouse-go driver to a version with correct type mapping.

Example fix

// before
SELECT amount FROM orders -- Decimal
// after
SELECT toString(amount) AS amount FROM orders
Defensive patterns

Strategy: try-catch

Validate before calling

// prefer SQL-side casts so values scan cleanly:
// SELECT toString(uuid_col), toFloat64(dec_col) FROM t

Try / catch

rows, err := src.RunSQL(ctx, stmt)
if err != nil {
    if strings.Contains(err.Error(), "unable to parse row") {
        return fmt.Errorf("scan failed: %w", err) // fix SQL casts or type handling
    }
    return err
}

Prevention

When it happens

Trigger: Scanning a row whose column value doesn't fit the expected Go type — e.g. unusual ClickHouse types (Decimal, UUID, arrays) returned by the driver in a form the scan targets can't hold.

Common situations: NULL values in non-pointer targets, exotic column types not handled by the switch on DatabaseTypeName, driver type mapping changes after upgrade.

Understand the failure class

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/ce95d64b28fb4362. Report an issue: GitHub.