{"record":{"id":"8b8ff6cd84a1fc05","repo":"apache/beam","slug":"bad-element-type","errorCode":null,"errorMessage":"bad element type","messagePattern":"bad element type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":431,"sourceCode":"\tcase reflect.Uint8:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_UINT8}, nil\n\tcase reflect.Uint16:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_UINT16}, nil\n\tcase reflect.Uint32:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_UINT32}, nil\n\tcase reflect.Uint64:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_UINT64}, nil\n\tcase reflect.Float32:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_FLOAT32}, nil\n\tcase reflect.Float64:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_FLOAT64}, nil\n\tcase reflect.String:\n\t\treturn &v1pb.Type{Kind: v1pb.Type_STRING}, nil\n\n\tcase reflect.Slice:\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 slice %v\", t)\n\t\t}\n\t\treturn &v1pb.Type{Kind: v1pb.Type_SLICE, Element: elm}, nil\n\n\tcase reflect.Struct:\n\t\tvar fields []*v1pb.Type_StructField\n\t\tfor i := 0; i < t.NumField(); i++ {\n\t\t\tf := t.Field(i)\n\n\t\t\tif f.PkgPath != \"\" {\n\t\t\t\twrapped := errors.Errorf(\"type has unexported field: %v\", f.Name)\n\t\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding struct %v\", t)\n\t\t\t}\n\n\t\t\tfType, err := encodeType(f.Type)\n\t\t\tif err != nil {\n\t\t\t\twrapped := errors.Wrap(err, \"bad field type\")\n\t\t\t\treturn nil, errors.WithContextf(wrapped, \"encoding struct %v\", t)","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L413-L449","documentation":"encodeType converts a Go reflect.Type to its protobuf Type representation. The 'bad element type' wrap with 'encoding slice' means the slice's element type itself failed to encode - encodeType recursion failed on t.Elem(). The failure propagates from deeper in the type tree (e.g. a slice of maps, which is explicitly unencodable).","triggerScenarios":"Serializing any type graph that includes a slice whose element (or nested element) hits an unencodable case: reflect.Map, reflect.Array, or an unsupported kind, inside encodeType.","commonSituations":"DoFn signatures or PCollections with element types like []map[string]int or [][]byte-containing structs with unexported fields; pipelines exported for remote runners.","solutions":["Inspect the full wrapped error context chain to find the deepest failing type in the slice element tree.","Replace map/array elements with slices or structs of exported fields.","Wrap unencodable element types as struct fields (beam issue 23101 workaround).","Register custom element types in the Beam type registry for EXTERNAL encoding."],"exampleFix":"// before\nfunc f(xs []map[string]int) { ... }\n// after\ntype Entry struct { K string; V int }\nfunc f(xs []Entry) { ... }","handlingStrategy":"validation","validationCode":"elm := reflect.TypeOf(xs).Elem()\nif err := isEncodableType(elm); err != nil {\n    return fmt.Errorf(\"slice element %v unencodable: %w\", elm, err)\n}","typeGuard":"func encodableSlice(s any) bool { t := reflect.TypeOf(s); return t.Kind() == reflect.Slice && isEncodableType(t.Elem()) == nil }","tryCatchPattern":"if err := isEncodableType(reflect.TypeOf(xs)); err != nil {\n    return fmt.Errorf(\"fix element type before export: %w\", err)\n}","preventionTips":["Avoid slices of maps/arrays as element types","Keep slice elements to primitives, strings, and exported-field structs","Read the wrapped 'encoding slice %v' context to identify the exact type"],"tags":["go","apache-beam","serialization","reflect"],"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"}