{"record":{"id":"5c62c1c088a1fa50","repo":"vitessio/vitess","slug":"s-v","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqltypes/bind_variables.go","lineNumber":71,"sourceCode":"\treturn &querypb.Value{Type: v.Type(), Value: v.val}\n}\n\n// ProtoToValue converts a *querypb.Value to a Value.\nfunc ProtoToValue(v *querypb.Value) Value {\n\treturn MakeTrusted(v.Type, v.Value)\n}\n\n// BuildBindVariables builds a map[string]*querypb.BindVariable from a map[string]any\nfunc BuildBindVariables(in map[string]any) (map[string]*querypb.BindVariable, error) {\n\tif len(in) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tout := make(map[string]*querypb.BindVariable, len(in))\n\tfor k, v := range in {\n\t\tbv, err := BuildBindVariable(v)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"%s: %v\", k, err)\n\t\t}\n\t\tout[k] = bv\n\t}\n\treturn out, nil\n}\n\n// HexNumBindVariable converts bytes representing a hex number to a bind var.\nfunc HexNumBindVariable(v []byte) *querypb.BindVariable {\n\treturn ValueBindVariable(NewHexNum(v))\n}\n\n// HexValBindVariable converts bytes representing a hex encoded string to a bind var.\nfunc HexValBindVariable(v []byte) *querypb.BindVariable {\n\treturn ValueBindVariable(NewHexVal(v))\n}\n\n// BitNumBindVariable converts bytes representing a bit encoded string to a bind var.\nfunc BitNumBindVariable(v []byte) *querypb.BindVariable {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/bind_variables.go#L53-L89","documentation":"BuildBindVariables converts a map of Go values into query bind variables. It wraps any per-key failure from BuildBindVariable with the offending key name, so this '%s: %v' error carries the unsupported key plus the underlying cause.","triggerScenarios":"Calling BuildBindVariables (used by ExecOnTablet / ExecOnVTGate) with a map containing a value whose type BuildBindVariable cannot encode (unsupported type, nil, bad slice, etc.).","commonSituations":"Passing custom structs, maps, or nil pointers as bind values; a refactor changed a value's type; JSON-decoded data produced interface{} values of unexpected types.","solutions":["Read the wrapped key and underlying message to find the offending bind variable","Convert the value to a supported type (scalar, []byte, time.Time, or a typed list) before calling","Pre-validate values with BuildBindVariable individually in a loop to isolate the bad key"],"exampleFix":"// before\nvars := map[string]interface{}{\"user\": user} // user is a struct\n// after\nvars := map[string]interface{}{\"user\": user.ID} // pass a supported scalar","handlingStrategy":"validation","validationCode":"func validateBindValues(in map[string]interface{}) error {\n\tfor k, v := range in {\n\t\tif _, err := sqltypes.BuildBindVariable(v); err != nil {\n\t\t\treturn fmt.Errorf(\"key %q: %v\", k, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":"func isBindable(v interface{}) bool {\n\tswitch v.(type) {\n\tcase nil, string, []byte, int, int8, int16, int32, int64,\n\t\tuint, uint8, uint16, uint32, uint64, float32, float64,\n\t\ttime.Time, *querypb.BindVariable:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"vars, err := sqltypes.BuildBindVariables(in)\nif err != nil {\n\treturn vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, \"bad bind vars: %v\", err)\n}","preventionTips":["Only pass scalars, []byte, time.Time, or supported slices as bind values","Never pass structs/maps as bind variables; serialize explicitly if needed","Check for typed-nil pointers before binding"],"tags":["go","sql","bind-variables","type-error"],"backgroundTag":"unsupported-bind-variable-type","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}