{"record":{"id":"793f17bf8e9b30e9","repo":"apache/beam","slug":"failed-to-encode-receiver-type-t","errorCode":null,"errorMessage":"failed to encode receiver type %T","messagePattern":"failed to encode receiver type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":253,"sourceCode":"\t\t\twrapped := errors.Wrap(err, \"bad userfn\")\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding DoFn %v\", u)\n\t\t}\n\t\treturn &v1pb.Fn{Fn: fn}, nil\n\n\tcase u.Recv != nil:\n\t\tt := reflect.TypeOf(u.Recv)\n\t\tk, ok := runtime.TypeKey(reflectx.SkipPtr(t))\n\t\tif !ok {\n\t\t\terr := errors.Errorf(\"failed to create TypeKey for receiver type %T\", u.Recv)\n\t\t\treturn nil, errors.WithContextf(err, \"encoding structural DoFn %v\", u)\n\t\t}\n\t\tif _, ok := runtime.LookupType(k); !ok {\n\t\t\terr := errors.Errorf(\"receiver type %v must be registered\", t)\n\t\t\treturn nil, errors.WithContextf(err, \"encoding structural DoFn %v\", u)\n\t\t}\n\t\ttyp, err := encodeType(t)\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrapf(err, \"failed to encode receiver type %T\", u.Recv)\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding structural DoFn %v\", u)\n\t\t}\n\n\t\tdata, err := jsonx.Marshal(u.Recv)\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrapf(err, \"failed to marshal receiver %v\", u.Recv)\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding structural DoFn %v\", u)\n\t\t}\n\t\treturn &v1pb.Fn{Type: typ, Opt: string(data)}, nil\n\n\tdefault:\n\t\treturn nil, errors.Errorf(\"failed to encode DoFn %v, missing fn\", u)\n\t}\n}\n\nfunc decodeFn(u *v1pb.Fn) (*graph.Fn, error) {\n\tif u.Dynfn != nil {\n\t\tgen, err := runtime.ResolveFunction(u.Dynfn.Gen, genFnType)","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L235-L271","documentation":"encodeFn fails to serialize the DoFn receiver's type via encodeType after the registration check passed. This means the type is registered but its type descriptor cannot be encoded into the pipeline proto, typically because it contains a component type graphx cannot represent.","triggerScenarios":"EncodeMultiEdge on a structural DoFn whose receiver type (or one of its type parameters) resolves to an unsupported/anonymous/unrepresentable type passed to encodeType.","commonSituations":"DoFns built with generics or reflection-created types that have no stable name; types with unnamed struct or interface components that the graphx type codec can't map to a named type.","solutions":["Inspect the wrapped cause from encodeType to see which component type is unrepresentable.","Replace anonymous/unnamed types with named, registered types.","Use a standard named struct DoFn instead of dynamically constructed types.","Update to a newer Beam version if the type is a normal named type (codec coverage has expanded over releases)."],"exampleFix":"// before\ntyp := reflect.StructOf([]reflect.StructField{{Name: \"X\", Type: reflect.TypeOf(0)}})\nfn := reflect.New(typ).Interface().(beam.DoFn)\n\n// after\ntype myFn struct{ X int }\nvar fn beam.DoFn = &myFn{}","handlingStrategy":"validation","validationCode":"if _, err := encodeType(reflect.TypeOf(myFn{})); err != nil {\n    return fmt.Errorf(\"receiver type not encodable: %w\", err)\n}","typeGuard":"func isNamedRegistered(t reflect.Type) bool {\n    return t.Name() != \"\" && t.PkgPath() != \"\"\n}","tryCatchPattern":null,"preventionTips":["Use named, top-level struct types for DoFns; avoid reflect.StructOf and anonymous types.","Test pipeline encoding locally with graphx.EncodeMultiEdge before submitting."],"tags":["go","serialization","type-encoding","apache-beam"],"backgroundTag":"type-encoding-failed","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"}