{"record":{"id":"ea9e9c0180b2541c","repo":"apache/beam","slug":"invalid-registration-type-v","errorCode":null,"errorMessage":"invalid registration type: %v","messagePattern":"invalid registration type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/types.go","lineNumber":39,"sourceCode":"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx\"\n)\n\nvar types = make(map[string]reflect.Type)\n\n// RegisterType inserts \"external\" types into a global type registry to bypass\n// serialization and preserve full method information. It should be called in\n// init() only. Returns the external key for the type.\nfunc RegisterType(t reflect.Type) string {\n\tif initialized {\n\t\tpanic(\"Init hooks have already run. Register type during init() instead.\")\n\t}\n\n\tt = reflectx.SkipPtr(t)\n\n\tk, ok := TypeKey(t)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"invalid registration type: %v\", t))\n\t}\n\n\tif v, exists := types[k]; exists && v != t {\n\t\tpanic(fmt.Sprintf(\"type already registered for %v, and new type %v != %v (existing type)\", k, t, v))\n\t}\n\ttypes[k] = t\n\treturn k\n}\n\n// LookupType looks up a type in the global type registry by external key.\nfunc LookupType(key string) (reflect.Type, bool) {\n\tt, ok := types[key]\n\treturn t, ok\n}\n\n// TypeKey returns the external key of a given type. Returns false if not a\n// candidate for registration.\nfunc TypeKey(t reflect.Type) (string, bool) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/types.go#L21-L57","documentation":"RegisterType derives a registry key via TypeKey(t), which only supports types with representable external keys (notably functions and certain unnamed/composite types are rejected). If no key can be derived, registering the type would be meaningless, so the library panics with the offending type.","triggerScenarios":"Passing a reflect.Type that TypeKey cannot handle — typically a func type without a proper named signature, an unexported/anonymous type, or a similarly unsupported kind (e.g. chan, interface) — to runtime.RegisterType (directly or via RegisterDoFn/RegisterCoder).","commonSituations":"Registering anonymous struct or func literals with reflect.TypeOf; registering a variable of interface or channel type by mistake; calling RegisterType on a DoFn wrapper type that isn't a struct.","solutions":["Register a named, concrete struct type (or pointer to it) instead of an anonymous/func/chan type.","Use reflect.TypeOf on a concrete instance value, not on an interface variable, so the dynamic type is registered.","If the type genuinely has no key (e.g. plain func), skip registry registration or wrap it in a named struct."],"exampleFix":"// before\nruntime.RegisterType(reflect.TypeOf(func(int) {})) // panics\n// after\ntype MyFn struct{}\nfunc (MyFn) ProcessElement(int) {}\nruntime.RegisterType(reflect.TypeOf(MyFn{}))","handlingStrategy":"type-guard","validationCode":"t := reflect.TypeOf(val)\nif t.Kind() == reflect.Func || t.Kind() == reflect.Chan || t.Name() == \"\" {\n    return fmt.Errorf(\"cannot register unsupported type %v\", t)\n}","typeGuard":"func registrable(t reflect.Type) bool {\n    t = reflectx.SkipPtr(t)\n    _, ok := runtime.TypeKey(t) // same check the library performs\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Only register named concrete types (structs and their pointers)","Avoid reflect.TypeOf on interface values or anonymous literals","Check TypeKey success before calling RegisterType in wrapper code"],"tags":["go","apache-beam","registration","reflection","panic"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}