{"record":{"id":"3c6b2b915d43a0d5","repo":"gocolly/colly","slug":"invalid-type","errorCode":null,"errorMessage":"Invalid type: ","messagePattern":"Invalid type: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"unmarshal.go","lineNumber":115,"sourceCode":"\t\t}\n\tcase reflect.String:\n\t\tvar val string\n\t\tif selector == \"\" && htmlAttr != \"\" {\n\t\t\tval = getDOMValue(s, htmlAttr)\n\t\t} else {\n\t\t\tval = getDOMValue(s.Find(selector), htmlAttr)\n\t\t}\n\t\tattrV.Set(reflect.Indirect(reflect.ValueOf(val)))\n\tcase reflect.Struct:\n\t\tif err := unmarshalStruct(s, selector, attrV); err != nil {\n\t\t\treturn err\n\t\t}\n\tcase reflect.Ptr:\n\t\tif err := unmarshalPtr(s, selector, attrV); err != nil {\n\t\t\treturn err\n\t\t}\n\tdefault:\n\t\treturn errors.New(\"Invalid type: \" + attrV.String())\n\t}\n\treturn nil\n}\n\nfunc unmarshalAttr(s *goquery.Selection, attrV reflect.Value, attrT reflect.StructField) error {\n\tselector := attrT.Tag.Get(\"selector\")\n\t//selector is \"-\" specify that field should ignore.\n\tif selector == \"-\" {\n\t\treturn nil\n\t}\n\thtmlAttr := attrT.Tag.Get(\"attr\")\n\t// TODO support more types\n\tswitch attrV.Kind() {\n\tcase reflect.Slice:\n\t\tif err := unmarshalSlice(s, selector, htmlAttr, attrV); err != nil {\n\t\t\treturn err\n\t\t}\n\tcase reflect.String:","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/gocolly/colly/blob/17d1d6ca92bd32a5651f34256bf7a2855c967f65/unmarshal.go#L97-L133","documentation":"unmarshalSelector maps a struct field tagged with `selector` to part of the DOM. It supports struct, slice, and pointer field kinds; any other kind (string, int, etc.) reaches the default branch and returns \"Invalid type: <value>\" (unmarshal.go:115). The value's kind is not a supported selector target.","triggerScenarios":"Declaring a struct field with a `selector:\"...\"` tag whose type is not struct, []struct, or *struct — e.g. a plain string field with a selector tag — then calling UnmarshalHTML/Unmarshal.","commonSituations":"Assuming `selector` tags work on scalar fields like strings; copying tags from struct-level examples onto primitive fields; schema drift after refactoring field types.","solutions":["Change the field type to a struct, *struct, or slice of structs","Move the selector tag to the struct level (on the struct type passed to UnmarshalHTML) for scalar capture via `map` tags or use `attr`-style handling","Remove the selector tag if the field is not meant for DOM binding","Check field kinds against the supported list in unmarshal.go"],"exampleFix":"// before\ntype Item struct {\n  Title string `selector:\"h1\"`\n}\n// after\ntype Title struct {\n  Text string `selector:\"h1\"`\n}\ntype Item struct {\n  Title Title `selector:\"\"`\n}","handlingStrategy":"validation","validationCode":"// before unmarshaling, verify selector-tagged fields are struct/slice/pointer kinds\nfor _, f := range reflect.VisibleFields(reflect.TypeOf(Item{})) {\n    if f.Tag.Get(\"selector\") != \"\" {\n        k := f.Type.Kind()\n        if k != reflect.Struct && k != reflect.Slice && k != reflect.Ptr {\n            panic(\"field \" + f.Name + \" has selector tag but unsupported kind\")\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := colly.UnmarshalHTML(&result, sel, nil); err != nil {\n    if strings.HasPrefix(err.Error(), \"Invalid type:\") {\n        log.Printf(\"schema error: %v\", err)\n    }\n    return err\n}","preventionTips":["Never put selector tags on scalar (string/int) fields","Keep a compile-time test that unmarshals a sample document in CI","Wrap scalars in structs when DOM binding is needed","Document the supported field kinds in your schema package"],"tags":["reflection","unmarshal","struct-tags","go"],"backgroundTag":"unsupported-field-type","analyzedSha":"17d1d6ca92bd32a5651f34256bf7a2855c967f65","analyzedAt":"2026-08-30T21:32:31.579Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}