{"record":{"id":"63359aa3ae771521","repo":"apache/beam","slug":"unsupported-type-for-clone-v","errorCode":null,"errorMessage":"unsupported type for clone: %v","messagePattern":"unsupported type for clone: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/util.go","lineNumber":58,"sourceCode":"\t\tfor i := 0; i < size; i++ {\n\t\t\tret.Index(i).Set(val.Index(i))\n\t\t}\n\t\treturn ret.Interface()\n\n\tcase reflect.Map:\n\t\tif val.IsNil() {\n\t\t\treturn reflect.Zero(t).Interface() // don't allocate for zero values\n\t\t}\n\n\t\tret := reflect.MakeMapWithSize(t, val.Len())\n\t\tkeys := val.MapKeys()\n\t\tfor _, key := range keys {\n\t\t\tret.SetMapIndex(key, val.MapIndex(key))\n\t\t}\n\t\treturn ret.Interface()\n\n\tcase reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:\n\t\tpanic(fmt.Sprintf(\"unsupported type for clone: %v\", t))\n\n\tdefault:\n\t\treturn v\n\t}\n}\n\n// UpdateMap merges two maps of type map[K]*V, with the second overwriting values\n// into the first (and mutating it). If the overwriting value is nil, the key is\n// deleted.\nfunc UpdateMap(base, updates any) {\n\tif updates == nil {\n\t\treturn // ok: nop\n\t}\n\tif base == nil {\n\t\tpanic(\"base map cannot be nil\")\n\t}\n\n\tm := reflect.ValueOf(base)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/util.go#L40-L76","documentation":"reflectx.ShallowClone shallowly copies maps, slices, pointers and structs, but cannot meaningfully clone arrays, channels, interfaces, funcs, or the Invalid kind. The library panics for these types because a shallow copy would either be impossible or semantically wrong.","triggerScenarios":"Calling ShallowClone on a value whose kind is Array, Chan, Interface, Func, or Invalid — e.g. cloning a graph component that wraps a function value or an uninitialized (zero reflect.Value).","commonSituations":"Beam pipeline cloning helpers (shallowClonePipeline, ShallowClonePTransform) encountering a component field of func/interface/array kind; cloning a nil-valued reflect.Value.","solutions":["Avoid storing func/chan/array/interface values in objects passed to ShallowClone, or wrap them in a cloneable struct.","Handle these kinds yourself before calling ShallowClone and pass only cloneable parts.","Ensure the reflect.Value is valid (not zero-valued) before cloning."],"exampleFix":"// before\nclone := reflectx.ShallowClone(reflect.ValueOf(someFunc)) // panics\n// after\nif v.Kind() == reflect.Func {\n    clone = v // funcs are shared, not cloned\n} else {\n    clone = reflectx.ShallowClone(v)\n}","handlingStrategy":"type-guard","validationCode":"switch v.Kind() {\ncase reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:\n    return fmt.Errorf(\"cannot shallow-clone kind %v\", v.Kind())\n}","typeGuard":"func cloneable(v reflect.Value) bool {\n    switch v.Kind() {\n    case reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:\n        return false\n    }\n    return true\n}","tryCatchPattern":"func safeClone(v reflect.Value) (out any, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"ShallowClone failed: %v\", r)\n        }\n    }()\n    return reflectx.ShallowClone(v), nil\n}","preventionTips":["Keep func/chan/interface values out of pipeline components that get cloned.","Verify reflect.Values are valid (not zero) before cloning."],"tags":["go","reflection","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}