{"record":{"id":"7bcdfd176b0fa173","repo":"kubernetes/kops","slug":"unhandled-type-v-q","errorCode":null,"errorMessage":"unhandled type %v %q","messagePattern":"unhandled type (.+?) %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/reflectutils/access.go","lineNumber":91,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\t// Partial match, check for nil struct and auto-populate\n\t\tif v.Kind() == reflect.Ptr && v.IsNil() {\n\t\t\tif !v.CanSet() {\n\t\t\t\treturn fmt.Errorf(\"cannot set field %q (marked immutable)\", path)\n\t\t\t}\n\n\t\t\tt := v.Type().String()\n\n\t\t\tvar newV reflect.Value\n\n\t\t\tswitch v.Type().Elem().Kind() {\n\t\t\tcase reflect.Struct:\n\t\t\t\tnewV = reflect.New(v.Type().Elem())\n\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"unhandled type %v %q\", v.Type().Elem().Kind(), t)\n\t\t\t}\n\n\t\t\tv.Set(newV)\n\t\t\treturn nil\n\n\t\t}\n\n\t\treturn nil\n\t}\n\n\terr = ReflectRecursive(targetValue, visitor, &ReflectOptions{JSONNames: true})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !fieldSet {\n\t\treturn fmt.Errorf(\"field %s not found in %s\", targetPath, BuildTypeName(reflect.TypeOf(target)))\n\t}","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/reflectutils/access.go#L73-L109","documentation":"During auto-population of a nil pointer on a partial path match, the library only knows how to allocate a pointer to a struct (reflect.New of a struct). If the nil pointer points to any other kind (string, int, map, slice, etc.) it cannot auto-create it and returns this error naming the element kind and type.","triggerScenarios":"SetString with a path traversing a nil *string/*int/*map field, e.g. targetPath \"spec.someNilStringPtr.sub\" where someNilStringPtr is *string and nil.","commonSituations":"Kops API objects gained new pointer-typed (non-struct) fields; users scripting `kops set` against paths that traverse such pointers, or custom structs fed to SetString that use *string indirection.","solutions":["Initialize the pointer field before calling SetString (e.g. s := \"\"; obj.Field = &s).","Restructure the target so the path traverses pointer-to-struct instead of pointer-to-scalar.","Set the leaf value directly instead of via a path that traverses the nil scalar pointer."],"exampleFix":"// before\nobj.MaxPrice = nil // *string, SetString cannot auto-create\nreflectutils.SetString(&obj, \"spec.maxPrice.value\", \"100\")\n// after\nobj.MaxPrice = new(string)\nreflectutils.SetString(&obj, \"spec.maxPrice.value\", \"100\")","handlingStrategy":"validation","validationCode":"// Fail fast if the path traverses a nil pointer-to-scalar\nif obj.MaxPrice == nil {\n    obj.MaxPrice = new(string)\n}","typeGuard":"func isPtrToStruct(v reflect.Value) bool {\n    return v.Kind() == reflect.Ptr && v.Type().Elem().Kind() == reflect.Struct\n}","tryCatchPattern":"if err := SetString(&obj, path, val); err != nil {\n    if strings.Contains(err.Error(), \"unhandled type\") {\n        return fmt.Errorf(\"path %q traverses a pointer SetString cannot allocate; initialize it first\", path)\n    }\n    return err\n}","preventionTips":["Prefer pointer-to-struct over pointer-to-scalar in mutation-path types.","Initialize nil pointers before calling SetString.","Prefer direct field assignment for exotic types."],"tags":["go","reflection","unsupported-type"],"backgroundTag":"unhandled-reflect-type","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}