{"record":{"id":"fe1b682a5b0de27a","repo":"vitessio/vitess","slug":"invalid-type-specified-for-makevalue-v","errorCode":null,"errorMessage":"invalid type specified for MakeValue: %v","messagePattern":"invalid type specified for MakeValue: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqltypes/value.go","lineNumber":120,"sourceCode":"\t\tif _, err := fastparse.ParseUint64(hack.String(val), 10); err != nil {\n\t\t\treturn NULL, err\n\t\t}\n\t\treturn MakeTrusted(typ, val), nil\n\tcase IsFloat(typ):\n\t\tif _, err := fastparse.ParseFloat64(hack.String(val)); err != nil {\n\t\t\treturn NULL, err\n\t\t}\n\t\treturn MakeTrusted(typ, val), nil\n\tcase IsDecimal(typ):\n\t\tif _, err := decimal.NewFromMySQL(val); err != nil {\n\t\t\treturn NULL, err\n\t\t}\n\t\treturn MakeTrusted(typ, val), nil\n\tcase IsQuoted(typ) || typ == Bit || typ == HexNum || typ == HexVal || typ == Null || typ == BitNum:\n\t\treturn MakeTrusted(typ, val), nil\n\t}\n\t// All other types are unsafe or invalid.\n\treturn NULL, fmt.Errorf(\"invalid type specified for MakeValue: %v\", typ)\n}\n\n// MakeTrusted makes a new Value based on the type.\n// This function should only be used if you know the value\n// and type conform to the rules. Every place this function is\n// called, a comment is needed that explains why it's justified.\n// Exceptions: The current package and mysql package do not need\n// comments. Other packages can also use the function to create\n// VarBinary or VarChar values.\nfunc MakeTrusted(typ querypb.Type, val []byte) Value {\n\tif typ == Null {\n\t\treturn NULL\n\t}\n\treturn Value{typ: uint16(typ), val: val}\n}\n\n// NewHexNum builds an Hex Value.\nfunc NewHexNum(v []byte) Value {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/value.go#L102-L138","documentation":"NewValue (MakeValue) builds a Value from bytes for a given type. Only numeric, datetime-ish, and quoted/hex/bit/null types are considered valid; anything else (e.g. Expression, Tuple types) is 'unsafe or invalid' for byte-backed values, so this error is returned with NULL.","triggerScenarios":"Calling NewValue/Cast with a querypb.Type that cannot be constructed from raw bytes, such as querypb.Type_EXPRESSION or a tuple type, often via ValidateBindVariable or structToQueryValue on user-supplied data.","commonSituations":"Reflect-driven code copying a type from an AST expression node into a value constructor; bind-variable validation receiving a type set programmatically to an invalid value.","solutions":["Only pass concrete data types (Int64, VarChar, Null, quoted types, etc.) to NewValue","Handle Expression/Tuple types separately before calling NewValue","Check sqltypes.IsQuoted/IsNumber guards before constructing"],"exampleFix":"// before\nval, err := sqltypes.NewValue(query.Type_EXPRESSION, []byte(\"x + 1\"))\n// after\nval := sqltypes.NewVarBinary(\"x + 1\")","handlingStrategy":"validation","validationCode":"func constructible(t querypb.Type) bool {\n  return sqltypes.IsNumber(t) || sqltypes.IsQuoted(t) ||\n    t == sqltypes.Bit || t == sqltypes.HexNum || t == sqltypes.HexVal ||\n    t == sqltypes.Null || t == sqltypes.BitNum ||\n    t == sqltypes.Timestamp || t == sqltypes.Date || t == sqltypes.Time || t == sqltypes.Datetime\n}","typeGuard":"func canMakeValue(t querypb.Type) bool { return constructible(t) }","tryCatchPattern":"val, err := sqltypes.NewValue(typ, bytes)\nif err != nil {\n  return vterrors.Wrapf(err, \"cannot build value for type %v\", typ)\n}","preventionTips":["Never feed Expression/Tuple types into NewValue","Sanitize programmatic types before constructing bind vars","Cover type construction in unit tests"],"tags":["sqltypes","type-validation","bind-variables"],"backgroundTag":"invalid-sql-type","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}