{"record":{"id":"f50114f4055e6294","repo":"kataras/iris","slug":"convert-struct-invalid-type-expected-a-struct-va","errorCode":null,"errorMessage":"convert struct: invalid type: expected a struct value but got: %q","messagePattern":"convert struct: invalid type: expected a struct value but got: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/sqlx/struct_row.go","lineNumber":19,"sourceCode":"package sqlx\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\n\t\"github.com/kataras/iris/v12/x/reflex\"\n)\n\n// DefaultTag is the default struct field tag.\nvar DefaultTag = \"db\"\n\n// ColumnNameFunc is the function which converts a struct field name to a database column name.\ntype ColumnNameFunc = func(string) string\n\nfunc convertStructToColumns(typ reflect.Type, nameFunc ColumnNameFunc) (map[string]*Column, error) {\n\tif kind := typ.Kind(); kind != reflect.Struct {\n\t\treturn nil, fmt.Errorf(\"convert struct: invalid type: expected a struct value but got: %q\", kind.String())\n\t}\n\n\t// Retrieve only fields valid for database.\n\tfields := reflex.LookupFields(typ, \"\")\n\n\tcolumns := make(map[string]*Column, len(fields))\n\tfor i, field := range fields {\n\t\tcolumn, ok, err := convertStructFieldToColumn(field, DefaultTag, nameFunc)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"convert struct: field name: %q: %w\", field.Name, err)\n\t\t}\n\n\t\tcolumn.Index = i\n\t\tcolumns[column.Name] = column","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/sqlx/struct_row.go#L1-L37","documentation":"convertStructToColumns only accepts reflect.Struct kinds when deriving the column map for a registered Row. Register was called with a type whose kind is not a struct (e.g. a pointer, slice, or primitive), so registration aborts with this message. It is a setup-time validation error.","triggerScenarios":"Calling Register with a *T (pointer type), []T (slice), map, or basic type instead of the struct type T itself.","commonSituations":"Passing reflect.TypeOf(&User{}) instead of reflect.TypeOf(User{}); generics/reflection helpers that hand back pointer types; refactoring a struct into a type alias.","solutions":["Pass the struct value type, not a pointer: reflect.TypeOf(User{}) not reflect.TypeOf(&User{})","Dereference: for t := typ; t.Kind() == reflect.Ptr; t = t.Elem()","Verify the argument is the model struct, not a DTO wrapper"],"exampleFix":"// before\nrow := NewRow(\"users\", reflect.TypeOf(&User{}))\n// after\nrow := NewRow(\"users\", reflect.TypeOf(User{}))","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(model)\nfor t != nil && t.Kind() == reflect.Ptr { t = t.Elem() }\nif t == nil || t.Kind() != reflect.Struct { return errors.New(\"Register requires a struct type\") }","typeGuard":"func isStructType(v any) bool {\n\tt := reflect.TypeOf(v)\n\tfor t != nil && t.Kind() == reflect.Ptr { t = t.Elem() }\n\treturn t != nil && t.Kind() == reflect.Struct\n}","tryCatchPattern":null,"preventionTips":["Pass reflect.TypeOf(Model{}), never of &Model{}","Dereference pointers before registration","Validate at init() time so failures surface at startup"],"tags":["reflection","registration","go"],"backgroundTag":"invalid-struct-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}