{"id":"c7a5dee657dea184","repo":"go-sql-driver/mysql","slug":"unsupported-type-t-a-s","errorCode":null,"errorMessage":"unsupported type %T, a %s","messagePattern":"unsupported type %T, a (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"statement.go","lineNumber":211,"sourceCode":"\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n\t\treturn rv.Uint(), nil\n\tcase reflect.Float32, reflect.Float64:\n\t\treturn rv.Float(), nil\n\tcase reflect.Bool:\n\t\treturn rv.Bool(), nil\n\tcase reflect.Slice:\n\t\tswitch t := rv.Type(); {\n\t\tcase t == jsonType:\n\t\t\treturn v, nil\n\t\tcase t.Elem().Kind() == reflect.Uint8:\n\t\t\treturn rv.Bytes(), nil\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unsupported type %T, a slice of %s\", v, t.Elem().Kind())\n\t\t}\n\tcase reflect.String:\n\t\treturn rv.String(), nil\n\t}\n\treturn nil, fmt.Errorf(\"unsupported type %T, a %s\", v, rv.Kind())\n}\n\nvar valuerReflectType = reflect.TypeFor[driver.Valuer]()\n\n// callValuerValue returns vr.Value(), with one exception:\n// If vr.Value is an auto-generated method on a pointer type and the\n// pointer is nil, it would panic at runtime in the panicwrap\n// method. Treat it like nil instead.\n//\n// This is so people can implement driver.Value on value types and\n// still use nil pointers to those types to mean nil/NULL, just like\n// string/*string.\n//\n// This is an exact copy of the same-named unexported function from the\n// database/sql package.\nfunc callValuerValue(vr driver.Valuer) (v driver.Value, err error) {\n\tif rv := reflect.ValueOf(vr); rv.Kind() == reflect.Ptr &&\n\t\trv.IsNil() &&","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/statement.go#L193-L229","documentation":"The driver's converter (statement.go:211) fell through its entire type switch: the value's reflect.Kind is none of pointer, integer, unsigned, float, bool, slice, or string, and the type does not implement driver.Valuer. This covers structs, maps, arrays, chans, and funcs that the driver cannot serialize.","triggerScenarios":"Passing a struct or map directly as an argument; passing a chan/func value; a nil interface wrapping an unhandled concrete type.","commonSituations":"Expecting automatic JSON serialization of a struct; passing a whole map as a parameter; submitting a domain object without extracting primitive fields.","solutions":["Marshal structs/maps to JSON and pass the resulting []byte.","Implement driver.Valuer on the custom type so Value() returns a base driver.Value.","Extract the specific primitive field(s) needed and pass those individually."],"exampleFix":"// before\ndb.Exec(\"INSERT INTO t(data) VALUES(?)\", myStruct)\n\n// after\nb, _ := json.Marshal(myStruct)\ndb.Exec(\"INSERT INTO t(data) VALUES(?)\", b)","handlingStrategy":"type-guard","validationCode":"func isSupportedArg(v any) bool {\n    if v == nil { return true }\n    if _, ok := v.(driver.Valuer); ok { return true }\n    switch reflect.ValueOf(v).Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n        reflect.Float32, reflect.Float64, reflect.Bool, reflect.String:\n        return true\n    }\n    return false\n}","typeGuard":"func supportedKind(k reflect.Kind) bool {\n    switch k {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n        reflect.Float32, reflect.Float64, reflect.Bool, reflect.String:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if _, err := db.Exec(q, v); err != nil {\n    if strings.Contains(err.Error(), \"unsupported type\") {\n        // marshal to []byte or implement driver.Valuer\n    }\n}","preventionTips":["Do not pass structs/maps directly; marshal them first.","Implement driver.Valuer for reusable custom types.","Extract primitive fields rather than passing whole structs."],"tags":["types","struct","conversion","api-misuse"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}