{"record":{"id":"8066dca7ec083ce1","repo":"vitessio/vitess","slug":"err-8066dc","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqltypes/testing.go","lineNumber":134,"sourceCode":"\t\tresult.Fields = nil\n\t\tresult.RowsAffected = 0\n\t\tresults = append(results, result)\n\t\tstart = cur + 1\n\t\tcur = start\n\t}\n\treturn results\n}\n\n// TestBindVariable makes a *querypb.BindVariable from any.\n// It panics on invalid input.\n// This function should only be used for testing.\nfunc TestBindVariable(v any) *querypb.BindVariable {\n\tif v == nil {\n\t\treturn NullBindVariable\n\t}\n\tbv, err := BuildBindVariable(v)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn bv\n}\n\n// TestValue builds a Value from typ and val.\n// This function should only be used for testing.\nfunc TestValue(typ querypb.Type, val string) Value {\n\treturn MakeTrusted(typ, []byte(val))\n}\n\n// TestTuple builds a tuple Value from a list of Values.\n// This function should only be used for testing.\nfunc TestTuple(vals ...Value) Value {\n\treturn Value{\n\t\ttyp: uint16(Tuple),\n\t\tval: encodeTuple(vals),\n\t}\n}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/testing.go#L116-L152","documentation":"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.","triggerScenarios":"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.).","commonSituations":"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.","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"],"exampleFix":"// before\nbv := sqltypes.TestBindVariable(myStruct{}) // panics\n// after\ndata, err := json.Marshal(myStruct{})\nrequire.NoError(t, err)\nbv := sqltypes.TestBindVariable(data)","handlingStrategy":"validation","validationCode":"if _, err := sqltypes.BuildBindVariable(v); err != nil {\n    // unsupported type — convert or handle before TestBindVariable\n}","typeGuard":"func isSupportedBindType(v any) bool {\n    switch v.(type) {\n    case nil, string, []byte, bool, int, int64, uint64, float64, time.Time:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Only pass scalar/known-supported types to TestBindVariable","Use BuildBindVariable directly when the value type is dynamic","Serialize structs/maps explicitly before binding"],"tags":["go","panic","testing","bind-variables"],"backgroundTag":"unsupported-value-type","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}