{"record":{"id":"abdf5aff56a5b4fd","repo":"apache/beam","slug":"failed-to-marshal-receiver-v","errorCode":null,"errorMessage":"failed to marshal receiver %v","messagePattern":"failed to marshal receiver (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":259,"sourceCode":"\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)\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrapf(err, \"bad symbol %v\", u.Dynfn.Gen)\n\t\t\treturn nil, errors.WithContextf(wrapped, \"decoding dynamic DoFn %v\", u)\n\t\t}\n\n\t\tt, err := decodeType(u.Dynfn.Type)","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L241-L277","documentation":"encodeFn marshals the DoFn receiver value to JSON (via jsonx.Marshal) to embed in the Fn proto's Opt field; this error means that JSON marshaling of the user's DoFn struct failed. Usually the struct contains fields JSON cannot represent (channels, funcs, unexported-only state, cycles).","triggerScenarios":"EncodeMultiEdge on a structural DoFn whose receiver contains a func, chan, complex number, cyclic reference, or a MarshalJSON implementation that errors.","commonSituations":"DoFn structs holding callback functions or channels for convenience; custom types with broken MarshalJSON methods; side-input state stored as unserializable fields.","solutions":["Remove func/chan/unserializable fields from the DoFn struct, or mark them `json:\"-\"` if they can be reconstructed.","Move non-serializable state out of the DoFn and pass it via side inputs or closure-free configuration.","Fix any custom MarshalJSON implementations on receiver fields.","Keep DoFn receiver as a plain data struct with JSON-safe exported fields."],"exampleFix":"// before\ntype myFn struct{ cb func(int) }\n\n// after\ntype myFn struct {\n    cb func(int) `json:\"-\"` // reinitialized in Setup()\n}","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(fn.Recv); err != nil {\n    return fmt.Errorf(\"DoFn receiver not JSON-serializable: %w\", err)\n}","typeGuard":"func jsonSafe(v interface{}) bool { _, err := json.Marshal(v); return err == nil }","tryCatchPattern":"_, err := json.Marshal(recv)\nif err != nil {\n    return fmt.Errorf(\"DoFn %T not serializable: %w\", recv, err)\n}","preventionTips":["Keep DoFn receiver structs free of func/chan fields or tag them `json:\"-\"`.","Unit-test json.Marshal on every custom DoFn value.","Initialize transient fields in Setup(), not in the struct literal."],"tags":["go","json","serialization","apache-beam"],"backgroundTag":"json-marshal-failed","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"}