{"record":{"id":"bbccdcbf062d4de0","repo":"apache/beam","slug":"bad-field-type","errorCode":null,"errorMessage":"bad field type","messagePattern":"bad field type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/serialize.go","lineNumber":448,"sourceCode":"\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)\n\t\t\t}\n\n\t\t\tfield := &v1pb.Type_StructField{\n\t\t\t\tName:      f.Name,\n\t\t\t\tPkgPath:   f.PkgPath,\n\t\t\t\tType:      fType,\n\t\t\t\tTag:       string(f.Tag),\n\t\t\t\tOffset:    int64(f.Offset),\n\t\t\t\tIndex:     encodeInts(f.Index),\n\t\t\t\tAnonymous: f.Anonymous,\n\t\t\t}\n\t\t\tfields = append(fields, field)\n\t\t}\n\t\treturn &v1pb.Type{Kind: v1pb.Type_STRUCT, Fields: fields}, nil\n\n\tcase reflect.Func:\n\t\tvar in []*v1pb.Type","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/serialize.go#L430-L466","documentation":"encodeType encodes each struct field's type recursively; 'bad field type' means one of the struct's field types failed to encode (e.g. a field of map or array type, which the wire format does not support). The error context names the struct being encoded so the offending field can be located.","triggerScenarios":"Serializing a struct (PCollection element or DoFn struct) where a field's reflect.Type hits an unencodable case in encodeType - most commonly map or array field kinds.","commonSituations":"Event records with embedded maps (e.g. Attributes map[string]string) streamed through a pipeline exported to a remote runner; nested structs containing arrays.","solutions":["Replace map/array struct fields with slices of key-value structs.","Wrap the map/array as a field of an inner struct per beam issue 23101 guidance (note the outer struct may still fail; convert to slice-of-structs is safer).","Apply a custom coder for the affected type so the default structural encoding is bypassed.","Read the wrapped context chain ('encoding struct X ... encoding ...') to pinpoint the offending field."],"exampleFix":"// before\ntype Record struct {\n    Tags map[string]string\n}\n// after\ntype Tag struct { K, V string }\ntype Record struct {\n    Tags []Tag\n}","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(rec)\nfor i := 0; i < t.NumField(); i++ {\n    if err := isEncodableType(t.Field(i).Type); err != nil {\n        return fmt.Errorf(\"field %s of %v unencodable: %w\", t.Field(i).Name, t, err)\n    }\n}","typeGuard":"func encodableStructFields(v any) bool { t := reflect.TypeOf(v); if t.Kind() != reflect.Struct { return false }; for i := 0; i < t.NumField(); i++ { if isEncodableType(t.Field(i).Type) != nil { return false } }; return true }","tryCatchPattern":"if err := isEncodableType(reflect.TypeOf(rec)); err != nil {\n    return fmt.Errorf(\"restructure struct %T (maps/arrays in fields): %w\", rec, err)\n}","preventionTips":["Replace map/array struct fields with slices of key-value structs","Apply custom coders for legacy types you cannot reshape","Validate record types early in pipeline construction, not at export time"],"tags":["go","apache-beam","serialization","struct"],"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"}