vitessio/vitess · error
unexpected type %T: %v
Error message
unexpected type %T: %v
What it means
InterfaceToValue converts a limited set of Go types (int64, uint64, float64, string and similar numeric cases above) into a sqltypes.Value. Any other Go dynamic type hits the default branch and returns this error naming the type and value.
Source
Thrown at go/sqltypes/value.go:315
// string and []byte.
// This function is deprecated. Use the type-specific
// functions instead.
func InterfaceToValue(goval any) (Value, error) {
switch goval := goval.(type) {
case nil:
return NULL, nil
case []byte:
return MakeTrusted(VarBinary, goval), nil
case int64:
return NewInt64(goval), nil
case uint64:
return NewUint64(goval), nil
case float64:
return NewFloat64(goval), nil
case string:
return NewVarChar(goval), nil
default:
return NULL, fmt.Errorf("unexpected type %T: %v", goval, goval)
}
}
// Type returns the type of Value.
func (v Value) Type() querypb.Type {
return querypb.Type(v.typ)
}
// Raw returns the internal representation of the value. For newer types,
// this may not match MySQL's representation.
func (v Value) Raw() []byte {
return v.val
}
// RawStr returns the internal representation of the value as a string instead
// of a byte slice. This is equivalent to calling `string(v.Raw())` but does
// not allocate.
func (v Value) RawStr() string {View on GitHub (pinned to 01a25a7d17)
Solutions
- Normalize the input to one of the supported types (int64/uint64/float64/string) before calling
- Convert bools to 0/1 ints, []byte to string, time.Time to formatted string
- For JSON values, marshal the nested value to a string and use a JSON-typed Value
Example fix
// before
v, err := sqltypes.InterfaceToValue(true)
// after
var i int64
if b { i = 1 }
v, err := sqltypes.InterfaceToValue(i) Defensive patterns
Strategy: validation
Validate before calling
func supportedGoType(v any) bool {
switch v.(type) {
case int64, uint64, float64, string:
return true
}
return false
} Type guard
func isScalar(v any) bool {
switch v.(type) {
case int64, uint64, float64, string:
return true
default:
return false
}
} Try / catch
v, err := sqltypes.InterfaceToValue(x)
if err != nil {
return sqltypes.NewVarBinary(fmt.Sprintf("%v", x)) // fallback
} Prevention
- Normalize bools/times/bytes before conversion
- Validate JSON bind variables against scalar-only schemas
- Add a switch default unit test for exotic inputs
When it happens
Trigger: Calling InterfaceToValue with e.g. bool, []byte, time.Time, nil, or a struct — typically via Value.UnmarshalJSON when a JSON bind variable contains a JSON object/array/bool rather than number or string.
Common situations: Unmarshaling JSON bind variables where users pass booleans, nested objects, or null; passing Go-native values from application code straight into vitess bind var conversion without normalizing.
Related errors
- unreachable
- Invalid JSON path expression.
- range %d should be >= %d
- too big depth for the nested JSON; it exceeds %d
- unexpected character %q in JSON
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/e9a7249850f1d1d4.
Report an issue: GitHub.