{"record":{"id":"0ba7939a2f3997ea","repo":"apache/beam","slug":"infercoder-failed-interface-type-v-has-no-coder-registered","errorCode":null,"errorMessage":"inferCoder failed: interface type %v has no coder registered","messagePattern":"inferCoder failed: interface type (.+?) has no coder registered","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/coder.go","lineNumber":241,"sourceCode":"\t\t\t\treturn coder.CoderFrom(c), nil\n\t\t\t}\n\n\t\t\tif EnableSchemas {\n\t\t\t\tswitch et.Kind() {\n\t\t\t\tcase reflect.Ptr:\n\t\t\t\t\tif et.Elem().Kind() != reflect.Struct {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tfallthrough\n\t\t\t\tcase reflect.Struct:\n\t\t\t\t\treturn &coder.Coder{Kind: coder.Row, T: t}, nil\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Interface types that implement JSON marshalling can be handled by the default coder.\n\t\t\t// otherwise, inference needs to fail here.\n\t\t\tif et.Kind() == reflect.Interface && !et.Implements(jsonCoderType) {\n\t\t\t\treturn nil, errors.Errorf(\"inferCoder failed: interface type %v has no coder registered\", et)\n\t\t\t}\n\n\t\t\tc, err := newJSONCoder(et)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn &coder.Coder{Kind: coder.Custom, T: t, Custom: c}, nil\n\t\t}\n\n\tcase typex.Composite:\n\t\tc, err := inferCoders(t.Components())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tswitch t.Type() {\n\t\tcase typex.KVType:\n\t\t\treturn &coder.Coder{Kind: coder.KV, T: t, Components: c}, nil","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/coder.go#L223-L259","documentation":"inferCoder tries to automatically pick a serialization coder for a Go type used in a PCollection. When it meets a reflect.Interface kind that does NOT implement JSON marshalling (json.Marshaler / encoding.TextMarshaler via jsonCoderType), no default coder exists and inference fails. The library refuses to guess a coder, so the user must register one explicitly.","triggerScenarios":"Passing a pipeline element whose static type is an interface (e.g. interface{}, a user-defined interface, or a typed nil-carrier) to NewCoder/NewElementEncoder/NewElementDecoder, inferCoders, or a Combine (TryCombinePerKey), when the concrete dynamic type's interface does not implement json.Marshaler/TextMarshaler.","commonSituations":"Using []interface{} or map[string]interface{} as a PCollection element; defining DoFn process elements as a custom interface type; upgrading Beam Go where a previously unexported type became an interface in a signature; par-do chains that pass values through generic interfaces.","solutions":["Make the PCollection element a concrete type (struct or named concrete type) instead of an interface type.","Implement json.Marshaler (and json.Unmarshaler) on the interface's concrete types so the default JSON coder can handle it.","Register an explicit coder via beam.NewCoder / coder.NewCustomCoder for the type and pass it to the transform (e.g. beam.ParDo(..., beam.TypeDefinition{}, col) with coder, or combine.TryCombinePerKey with an explicit accum coder).","Check the type at the failing call site: print reflect.TypeOf(value).Kind(); if it is reflect.Interface, restructure to a concrete element type."],"exampleFix":"// before\nbeam.ParDo(s, &MyFn{}, col) // element type is interface{}\n\n// after\ntype MyElem struct { Value string }\nbeam.ParDo(s, &MyFn{}, beam.ParDo(s, &ConcretizeFn{}, col), beam.TypeDefinition{Var: typex.NewVariable(0), T: reflect.TypeOf(MyElem{})})\n// or implement MarshalJSON/UnmarshalJSON on the concrete types","handlingStrategy":"validation","validationCode":"func canInferCoder(t reflect.Type) error {\n  if t.Kind() == reflect.Interface && !t.Implements(jsonCoderType) {\n    return fmt.Errorf(\"interface %v needs an explicit coder; use a concrete type or register one\", t)\n  }\n  return nil\n}","typeGuard":"func isCoderable(t reflect.Type) bool {\n  return t != nil && (t.Kind() != reflect.Interface || t.Implements(jsonCoderType))\n}","tryCatchPattern":null,"preventionTips":["Use concrete struct types for PCollection elements, never interface{} or bare interfaces.","Implement json.Marshaler/Unmarshaler on types flowing through pipelines.","Register explicit coders (beam.NewCoder / coder.NewCustomCoder) for custom types before pipeline construction.","Add a unit test that calls beam.NewCoder(reflect.TypeOf(elem{})) for every element type you use."],"tags":["go","beam","coder-inference","reflection"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}