apache/beam · error
unsupported type for clone
Error message
unsupported type for clone: %v
What it means
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.
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.
Example fix
// before
clone := reflectx.ShallowClone(reflect.ValueOf(someFunc)) // panics
// after
if v.Kind() == reflect.Func {
clone = v // funcs are shared, not cloned
} else {
clone = reflectx.ShallowClone(v)
} Defensive patterns
Strategy: type-guard
Validate before calling
switch v.Kind() {
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:
return fmt.Errorf("cannot shallow-clone kind %v", v.Kind())
} Type guard
func cloneable(v reflect.Value) bool {
switch v.Kind() {
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:
return false
}
return true
} Try / catch
func safeClone(v reflect.Value) (out any, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ShallowClone failed: %v", r)
}
}()
return reflectx.ShallowClone(v), nil
} Prevention
- Keep func/chan/interface values out of pipeline components that get cloned.
- Verify reflect.Values are valid (not zero) before cloning.
When it happens
Trigger: 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).
Common situations: Beam pipeline cloning helpers (shallowClonePipeline, ShallowClonePTransform) encountering a component field of func/interface/array kind; cloning a nil-valued reflect.Value.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- bad decode
- bad encode
- bad return type for
- base map cannot be nil
- beam.RegisterSchemaProvider: unsupported type kind for…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/63359aa3ae771521.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/util.go:58
for i := 0; i < size; i++ {
ret.Index(i).Set(val.Index(i))
}
return ret.Interface()
case reflect.Map:
if val.IsNil() {
return reflect.Zero(t).Interface() // don't allocate for zero values
}
ret := reflect.MakeMapWithSize(t, val.Len())
keys := val.MapKeys()
for _, key := range keys {
ret.SetMapIndex(key, val.MapIndex(key))
}
return ret.Interface()
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:
panic(fmt.Sprintf("unsupported type for clone: %v", t))
default:
return v
}
}
// UpdateMap merges two maps of type map[K]*V, with the second overwriting values
// into the first (and mutating it). If the overwriting value is nil, the key is
// deleted.
func UpdateMap(base, updates any) {
if updates == nil {
return // ok: nop
}
if base == nil {
panic("base map cannot be nil")
}
m := reflect.ValueOf(base)View on GitHub (pinned to 12126d8942)