{"record":{"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/03d76c7e07908e255ce62d126d07ede3f2365d86/statement.go#L193-L229","documentation":"ConvertValue's final fallback: the value's reflect.Kind is not a pointer/int-family/uint-family/float/bool/slice/string - e.g. a struct, map, chan, func, array, or interface. The driver cannot serialize such a value to the MySQL protocol.","triggerScenarios":"Passing a struct, map, chan, func, or array as a prepared-statement argument - e.g. passing a model struct instead of one of its scalar fields.","commonSituations":"Accidentally passing a whole model/config struct; plumbing the wrong variable into Exec.","solutions":["Pass a supported primitive field from the struct (e.g. s.ID instead of s).","Implement driver.Valuer on the type to convert it to a supported primitive.","Marshal the value to []byte/string (JSON) if it represents a complex payload."],"exampleFix":"// before\ntype User struct{ ID int64; Name string }\nstmt.Exec(User{1, \"a\"}) // SQL: INSERT INTO t VALUES (?)\n// after\nstmt.Exec(User{1, \"a\"}.ID)","handlingStrategy":"validation","validationCode":"// Reject unsupported kinds before Exec.\nfunc supportedKind(v any) bool {\n    switch reflect.ValueOf(v).Kind() {\n    case reflect.Struct, reflect.Map, reflect.Chan, reflect.Func, reflect.Array:\n        return false\n    }\n    return true\n}","typeGuard":"func isConvertible(v any) bool {\n    if _, ok := v.(driver.Valuer); ok { return true }\n    switch reflect.ValueOf(v).Kind() {\n    case reflect.Struct, reflect.Map, reflect.Chan, reflect.Func, reflect.Array:\n        return false\n    }\n    return true\n}","tryCatchPattern":"// Returned from Exec/Query for unsupported argument kinds.\nif _, err := stmt.Exec(args...); err != nil {\n    if strings.Contains(err.Error(), \"unsupported type\") {\n        // pass a primitive field or implement driver.Valuer\n    }\n}","preventionTips":["Pass scalar fields, not whole structs, to Exec.","Implement driver.Valuer for types you routinely store.","Add a guard rejecting struct/map/chan/func args."],"tags":["go","mysql","types","prepared-statement"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}