googleapis/mcp-toolbox · error

unexpected receiver type: %T

Error message

unexpected receiver type: %T

What it means

This is an internal invariant check: after scanning, RunSQL switches on the concrete type of each pre-allocated receiver, and this error fires if a receiver type falls outside the known set (*NullInt64, *NullFloat64, *NullString, *NullTime, *RawBytes). In practice it means a receiver in the values slice was never assigned by the colTypes loop — usually because len(cols) != len(colTypes) or the slice was built with a different length — leaving a nil (or wrong-typed) slot.

Source

Thrown at internal/sources/oracle/oracle.go:249

				}
			case *sql.NullTime:
				if v.Valid {
					vMap[col] = v.Time
				} else {
					vMap[col] = nil
				}
			case *sql.RawBytes:
				if *v != nil {
					var unmarshaledData any
					if err := json.Unmarshal(*v, &unmarshaledData); err != nil {
						return nil, fmt.Errorf("unable to unmarshal json data for column %s", col)
					}
					vMap[col] = unmarshaledData
				} else {
					vMap[col] = nil
				}
			default:
				return nil, fmt.Errorf("unexpected receiver type: %T", v)
			}
		}
		out = append(out, vMap)
	}

	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("errors encountered during query execution or row processing: %w", err)
	}

	return out, nil
}

func buildGoOraConnString(user, password, connectStringBase, walletLocation string) string {
	userInfo := url.UserPassword(
		decodePercentEncodedUserInfo(user),
		decodePercentEncodedUserInfo(password),
	).String()

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Confirm the Columns()/ColumnTypes() length mismatch: guard by checking len(cols) == len(colTypes) before iterating and returning a clearer error otherwise.
  2. Check whether the table was altered (DDL) concurrently with the query; retry after the DDL settles.
  3. Capture the error from rows.Columns() instead of discarding it so description failures surface early with a clearer message.
  4. Upgrade or pin the driver (godror/go-ora) version, since mismatched result description is typically a driver-level issue.

Example fix

// before
cols, _ := rows.Columns()
colTypes, err := rows.ColumnTypes()

// after
cols, err := rows.Columns()
if err != nil { return nil, fmt.Errorf("unable to get columns: %w", err) }
colTypes, err := rows.ColumnTypes()
if err != nil { return nil, fmt.Errorf("unable to get column types: %w", err) }
if len(cols) != len(colTypes) { return nil, fmt.Errorf("column/type count mismatch: %d vs %d", len(cols), len(colTypes)) }
Defensive patterns

Strategy: fallback

Validate before calling

rows, err := db.QueryContext(ctx, stmt)
if err != nil { return err }
cols, err := rows.Columns()
if err != nil { return fmt.Errorf("column description failed: %w", err) }
colTypes, err := rows.ColumnTypes()
if err != nil { return fmt.Errorf("column type description failed: %w", err) }
if len(cols) != len(colTypes) { return fmt.Errorf("result description mismatch: %d columns vs %d types", len(cols), len(colTypes)) }

Try / catch

out, err := source.RunSQL(ctx, stmt, params, true)
if err != nil && strings.Contains(err.Error(), "unexpected receiver type") {
    // result-set description was unstable; retry the query once
    out, err = source.RunSQL(ctx, stmt, params, true)
}
if err != nil { return err }

Prevention

When it happens

Trigger: RunSQL (readOnly=true) where rows.Columns() and rows.ColumnTypes() return different lengths (the Columns() error is deliberately swallowed at line 171, leaving cols empty/short while colTypes is populated, or vice versa); or a driver returning a receiver arrangement the switch doesn't recognize after a code change.

Common situations: Queries whose result-set description is unstable (driver bug, mid-flight schema change); concurrent DDL altering the queried table while the cursor is described; driver versions where Columns() errors but ColumnTypes() succeeds, causing cols/colTypes length mismatch and nil receivers.

Related errors


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