{"record":{"id":"e9a7249850f1d1d4","repo":"vitessio/vitess","slug":"unexpected-type-t-v","errorCode":null,"errorMessage":"unexpected type %T: %v","messagePattern":"unexpected type %T: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqltypes/value.go","lineNumber":315,"sourceCode":"// string and []byte.\n// This function is deprecated. Use the type-specific\n// functions instead.\nfunc InterfaceToValue(goval any) (Value, error) {\n\tswitch goval := goval.(type) {\n\tcase nil:\n\t\treturn NULL, nil\n\tcase []byte:\n\t\treturn MakeTrusted(VarBinary, goval), nil\n\tcase int64:\n\t\treturn NewInt64(goval), nil\n\tcase uint64:\n\t\treturn NewUint64(goval), nil\n\tcase float64:\n\t\treturn NewFloat64(goval), nil\n\tcase string:\n\t\treturn NewVarChar(goval), nil\n\tdefault:\n\t\treturn NULL, fmt.Errorf(\"unexpected type %T: %v\", goval, goval)\n\t}\n}\n\n// Type returns the type of Value.\nfunc (v Value) Type() querypb.Type {\n\treturn querypb.Type(v.typ)\n}\n\n// Raw returns the internal representation of the value. For newer types,\n// this may not match MySQL's representation.\nfunc (v Value) Raw() []byte {\n\treturn v.val\n}\n\n// RawStr returns the internal representation of the value as a string instead\n// of a byte slice. This is equivalent to calling `string(v.Raw())` but does\n// not allocate.\nfunc (v Value) RawStr() string {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/value.go#L297-L333","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nv, err := sqltypes.InterfaceToValue(true)\n// after\nvar i int64\nif b { i = 1 }\nv, err := sqltypes.InterfaceToValue(i)","handlingStrategy":"validation","validationCode":"func supportedGoType(v any) bool {\n  switch v.(type) {\n  case int64, uint64, float64, string:\n    return true\n  }\n  return false\n}","typeGuard":"func isScalar(v any) bool {\n  switch v.(type) {\n  case int64, uint64, float64, string:\n    return true\n  default:\n    return false\n  }\n}","tryCatchPattern":"v, err := sqltypes.InterfaceToValue(x)\nif err != nil {\n  return sqltypes.NewVarBinary(fmt.Sprintf(\"%v\", x)) // fallback\n}","preventionTips":["Normalize bools/times/bytes before conversion","Validate JSON bind variables against scalar-only schemas","Add a switch default unit test for exotic inputs"],"tags":["sqltypes","type-conversion","json"],"backgroundTag":"unsupported-type-conversion","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}