{"record":{"id":"47daf3ab36144399","repo":"apache/beam","slug":"invalid-value-v","errorCode":null,"errorMessage":"invalid value: %v","messagePattern":"invalid value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":766,"sourceCode":"\nfunc decodeInts(offsets []int32) []int {\n\tvar ret []int\n\tfor _, elm := range offsets {\n\t\tret = append(ret, int(elm))\n\t}\n\treturn ret\n}\n\nfunc encodeChanDir(dir reflect.ChanDir) (v1pb.Type_ChanDir, error) {\n\tswitch dir {\n\tcase reflect.RecvDir:\n\t\treturn v1pb.Type_RECV, nil\n\tcase reflect.SendDir:\n\t\treturn v1pb.Type_SEND, nil\n\tcase reflect.BothDir:\n\t\treturn v1pb.Type_BOTH, nil\n\tdefault:\n\t\terr := errors.Errorf(\"invalid value: %v\", dir)\n\t\treturn v1pb.Type_BOTH, errors.WithContextf(err, \"encoding channel direction\")\n\t}\n}\n\nfunc decodeChanDir(dir v1pb.Type_ChanDir) (reflect.ChanDir, error) {\n\tswitch dir {\n\tcase v1pb.Type_RECV:\n\t\treturn reflect.RecvDir, nil\n\tcase v1pb.Type_SEND:\n\t\treturn reflect.SendDir, nil\n\tcase v1pb.Type_BOTH:\n\t\treturn reflect.BothDir, nil\n\tdefault:\n\t\terr := errors.Errorf(\"invalid value: %v\", dir)\n\t\treturn reflect.BothDir, errors.WithContext(err, \"decoding channel direction\")\n\t}\n}\n","sourceCodeStart":748,"sourceCodeEnd":784,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L748-L784","documentation":"encodeChanDir failed to map a reflect.ChanDir to its v1pb.Type_ChanDir proto counterpart. Only RecvDir, SendDir, and BothDir are valid; any other value indicates corrupt reflect.Type metadata. Note the function returns Type_BOTH alongside the error, so a mishandled caller could silently mis-encode.","triggerScenarios":"encodeType encodes a channel-typed value whose t.ChanDir() is not one of reflect.RecvDir/SendDir/BothDir — essentially only possible with corrupted reflect metadata or misuse of the internal API with a synthetic dir value.","commonSituations":"Rarely hit in practice; mostly from direct use of internal graphx encoders or unusual reflect.Type implementations in tests.","solutions":["Verify the reflect.Type being encoded is obtained from genuine Go reflect calls (reflect.ChanOf, etc.), not fabricated","Check for nil/garbage ChanDir by logging reflect.TypeOf(value).ChanDir() before encoding","Update to a current Go toolchain and Beam SDK to rule out reflect incompatibilities","Handle the returned error rather than ignoring it, since Type_BOTH is returned with the error"],"exampleFix":"// before: ignoring the error\npb, _ := encodeChanDir(t.ChanDir())\n\n// after\npb, err := encodeChanDir(t.ChanDir())\nif err != nil {\n    return fmt.Errorf(\"encoding chan type %v: %w\", t, err)\n}","handlingStrategy":"type-guard","validationCode":"dir := t.ChanDir()\nif dir != reflect.RecvDir && dir != reflect.SendDir && dir != reflect.BothDir {\n    return fmt.Errorf(\"invalid chan dir %v for type %v\", dir, t)\n}","typeGuard":"func validChanDir(d reflect.ChanDir) bool {\n    return d == reflect.RecvDir || d == reflect.SendDir || d == reflect.BothDir\n}","tryCatchPattern":"pb, err := encodeChanDir(t.ChanDir())\nif err != nil {\n    return fmt.Errorf(\"cannot encode channel type %v: %w\", t, err)\n}","preventionTips":["Only encode reflect.Type values obtained from real Go reflection","Always check the error return; the function returns a default value alongside the error","Keep the Go toolchain and Beam SDK current"],"tags":["beam","go","serialization","reflection","channel"],"backgroundTag":"invalid-enum-value","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"}