vitessio/vitess · error
err
Error message
err
What it means
sqltypes.TestBindVariable is a test-only helper that builds a *querypb.BindVariable from an arbitrary Go value. It panics if BuildBindVariable rejects the value, since in tests a bind variable should always be constructible. Passing a value of an unsupported type turns a silent failure into an immediate test crash.
Source
Thrown at go/sqltypes/testing.go:134
result.Fields = nil
result.RowsAffected = 0
results = append(results, result)
start = cur + 1
cur = start
}
return results
}
// TestBindVariable makes a *querypb.BindVariable from any.
// It panics on invalid input.
// This function should only be used for testing.
func TestBindVariable(v any) *querypb.BindVariable {
if v == nil {
return NullBindVariable
}
bv, err := BuildBindVariable(v)
if err != nil {
panic(err)
}
return bv
}
// TestValue builds a Value from typ and val.
// This function should only be used for testing.
func TestValue(typ querypb.Type, val string) Value {
return MakeTrusted(typ, []byte(val))
}
// TestTuple builds a tuple Value from a list of Values.
// This function should only be used for testing.
func TestTuple(vals ...Value) Value {
return Value{
typ: uint16(Tuple),
val: encodeTuple(vals),
}
}View on GitHub (pinned to 01a25a7d17)
Solutions
- Pass only supported scalar types (int/int64/uint64/float64/string/[]byte/bool/time.Time or nil)
- Convert unsupported values to a supported representation (e.g. fmt.Sprintf to string or serialize to []byte) before wrapping
- Use BuildBindVariable directly and handle the error when the value type is uncertain
Example fix
// before
bv := sqltypes.TestBindVariable(myStruct{}) // panics
// after
data, err := json.Marshal(myStruct{})
require.NoError(t, err)
bv := sqltypes.TestBindVariable(data) Defensive patterns
Strategy: validation
Validate before calling
if _, err := sqltypes.BuildBindVariable(v); err != nil {
// unsupported type — convert or handle before TestBindVariable
} Type guard
func isSupportedBindType(v any) bool {
switch v.(type) {
case nil, string, []byte, bool, int, int64, uint64, float64, time.Time:
return true
}
return false
} Prevention
- Only pass scalar/known-supported types to TestBindVariable
- Use BuildBindVariable directly when the value type is dynamic
- Serialize structs/maps explicitly before binding
When it happens
Trigger: Calling TestBindVariable(v) with a v whose type BuildBindVariable does not support (e.g. a struct, map, channel, or a custom type outside the supported set: numbers, strings, bytes, bools, time, nil, etc.).
Common situations: Test refactors passing typed helper structs or pointers instead of primitives; passing a typed nil that isn't handled; using TestBindVariable outside unit tests where runtime errors would be preferable.
Related errors
- %s: %v
- type %T not supported as bind var: %v
- cannot parse VTPORTSTART: %v
- panic: %v
- SetIdleTimeout called when timer not initialized
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/8066dca7ec083ce1.
Report an issue: GitHub.