googleapis/mcp-toolbox · error

errors encountered when converting values: %w

Error message

errors encountered when converting values: %w

What it means

RunSQL wraps mysqlcommon.ConvertToType(colTypes[i], val) errors with this message. After a row is scanned, each column's raw value is converted to a proper Go type based on the column's database type; a failure means a value in the row could not be represented as the expected type.

Source

Thrown at internal/sources/singlestore/singlestore.go:155

	}

	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 {
			val := rawValues[i]
			if val == nil {
				vMap[name] = nil
				continue
			}

			vMap[name], err = mysqlcommon.ConvertToType(colTypes[i], val)
			if err != nil {
				return nil, fmt.Errorf("errors encountered when converting values: %w", err)
			}
		}
		out = append(out, vMap)
	}

	if err := results.Err(); err != nil {
		return nil, fmt.Errorf("errors encountered during row iteration: %w", err)
	}

	return out, nil
}

func initSingleStoreConnectionPool(ctx context.Context, tracer trace.Tracer, cfg Config) (*sql.DB, error) {
	//nolint:all // Reassigned ctx
	ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, cfg.Name)
	defer span.End()

	// Build query parameters via url.Values for deterministic order and proper escaping.

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped ConvertToType error to find the offending column and value.
  2. Fix or clean the invalid data in the table (e.g. zero-date rows).
  3. CAST the problem column to a simpler type in the SQL statement.
  4. Ensure time zone / parseTime DSN settings match the data (add parseTime=true or loc params via connectionParams).
  5. Check data types are as expected with `DESCRIBE table` and adjust the query.

Example fix

// before
SELECT * FROM logs
// after
SELECT id, CAST(event_time AS CHAR) AS event_time FROM logs
Defensive patterns

Strategy: validation

Validate before calling

-- Inspect data quality before querying
SELECT COUNT(*) FROM my_table WHERE ts = '0000-00-00' OR ts IS NULL;
DESCRIBE my_table;

Try / catch

out, err := source.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "errors encountered when converting values") {
    // retry with sanitized query that CASTs the offending column
    out, err = source.RunSQL(ctx, sanitizedStmt, params)
}

Prevention

When it happens

Trigger: A scanned value (e.g. []byte, time.Time, decimal string) fails type conversion for its declared column type in ConvertToType — malformed data in the column, or a column type the converter does not support.

Common situations: Invalid stored dates/timestamps (e.g. zero dates), numeric overflow for the target Go type, unsupported column types like custom encodings, or NULLs slipping through as non-nil placeholders.

Related errors


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