{"record":{"id":"304d519b51187ef6","repo":"apache/beam","slug":"bad-channel-direction","errorCode":null,"errorMessage":"bad channel direction","messagePattern":"bad channel direction","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":494,"sourceCode":"\t\tfor i := 0; i < t.NumOut(); i++ {\n\t\t\tret, err := encodeType(t.Out(i))\n\t\t\tif err != nil {\n\t\t\t\twrapped := errors.Wrap(err, \"bad return type\")\n\t\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding function %v\", t)\n\t\t\t}\n\t\t\tout = append(out, ret)\n\t\t}\n\t\treturn &v1pb.Type{Kind: v1pb.Type_FUNC, ParameterTypes: in, ReturnTypes: out, IsVariadic: t.IsVariadic()}, nil\n\n\tcase reflect.Chan:\n\t\telm, err := encodeType(t.Elem())\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrap(err, \"bad element type\")\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding channel %v\", t)\n\t\t}\n\t\tdir, err := encodeChanDir(t.ChanDir())\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrap(err, \"bad channel direction\")\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding channel %v\", t)\n\t\t}\n\t\treturn &v1pb.Type{Kind: v1pb.Type_CHAN, Element: elm, ChanDir: dir}, nil\n\n\tcase reflect.Ptr:\n\t\telm, err := encodeType(t.Elem())\n\t\tif err != nil {\n\t\t\twrapped := errors.Wrap(err, \"bad base type\")\n\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding pointer %v\", t)\n\t\t}\n\t\treturn &v1pb.Type{Kind: v1pb.Type_PTR, Element: elm}, nil\n\n\tcase reflect.Map, reflect.Array:\n\t\treturn nil, errors.Errorf(\"unencodable type '%v', try to wrap the type as a field in a struct, see https://github.com/apache/beam/issues/23101 for details\", t.Kind())\n\n\tdefault:\n\t\treturn nil, errors.Errorf(\"unencodable type '%v'\", t.Kind())\n\t}","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L476-L512","documentation":"encodeType encodes channel types together with their direction via encodeChanDir; 'bad channel direction' means the channel's reflect.ChanDir could not be mapped to a protobuf ChanDir value. This is an internal mapping failure - the SDK's encodeChanDir only covers RecvDir, SendDir, and BothDir, so it should be unreachable for valid reflect types and signals an internal invariant violation or corrupted type metadata.","triggerScenarios":"encodeType's reflect.Chan branch calls encodeChanDir with a direction outside the three valid reflect.ChanDir values - practically only via corrupted reflect metadata or an SDK-internal bug; triggered during pipeline graph export of a type containing a channel.","commonSituations":"Extremely rare; encountered when hacking reflect metadata, using unusual reflect constructs, or hitting a genuine Beam SDK bug while serializing channel-bearing types on remote runner export.","solutions":["Report/verify against the Beam SDK version; upgrade to the latest patch release.","Avoid channel types in serialized pipeline graphs entirely so this branch is never hit.","Check whether a custom type wrapper is producing an invalid reflect.Type and fix it.","File an issue with apache/beam including the wrapped error context ('encoding channel %v')."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := graphx.EncodeFn(fn); err != nil && strings.Contains(err.Error(), \"bad channel direction\") {\n    return fmt.Errorf(\"likely Beam SDK bug; report with context: %w\", err)\n}","preventionTips":["Keep the Beam Go SDK up to date to pick up internal mapping fixes","Avoid channel types in serialized pipeline graphs so this branch never executes","Report occurrences to apache/beam with the full wrapped error chain"],"tags":["go","apache-beam","serialization","internal-invariant"],"backgroundTag":"unencodable-reflect-type","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"}