apache/beam · error
invalid value
Error message
invalid value: %v
What it means
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.
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
Example fix
// before: ignoring the error
pb, _ := encodeChanDir(t.ChanDir())
// after
pb, err := encodeChanDir(t.ChanDir())
if err != nil {
return fmt.Errorf("encoding chan type %v: %w", t, err)
} Defensive patterns
Strategy: type-guard
Validate before calling
dir := t.ChanDir()
if dir != reflect.RecvDir && dir != reflect.SendDir && dir != reflect.BothDir {
return fmt.Errorf("invalid chan dir %v for type %v", dir, t)
} Type guard
func validChanDir(d reflect.ChanDir) bool {
return d == reflect.RecvDir || d == reflect.SendDir || d == reflect.BothDir
} Try / catch
pb, err := encodeChanDir(t.ChanDir())
if err != nil {
return fmt.Errorf("cannot encode channel type %v: %w", t, err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Rarely hit in practice; mostly from direct use of internal graphx encoders or unusual reflect.Type implementations in tests.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/47daf3ab36144399.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/graphx/serialize.go:766
func decodeInts(offsets []int32) []int {
var ret []int
for _, elm := range offsets {
ret = append(ret, int(elm))
}
return ret
}
func encodeChanDir(dir reflect.ChanDir) (v1pb.Type_ChanDir, error) {
switch dir {
case reflect.RecvDir:
return v1pb.Type_RECV, nil
case reflect.SendDir:
return v1pb.Type_SEND, nil
case reflect.BothDir:
return v1pb.Type_BOTH, nil
default:
err := errors.Errorf("invalid value: %v", dir)
return v1pb.Type_BOTH, errors.WithContextf(err, "encoding channel direction")
}
}
func decodeChanDir(dir v1pb.Type_ChanDir) (reflect.ChanDir, error) {
switch dir {
case v1pb.Type_RECV:
return reflect.RecvDir, nil
case v1pb.Type_SEND:
return reflect.SendDir, nil
case v1pb.Type_BOTH:
return reflect.BothDir, nil
default:
err := errors.Errorf("invalid value: %v", dir)
return reflect.BothDir, errors.WithContext(err, "decoding channel direction")
}
}
View on GitHub (pinned to 12126d8942)