{"record":{"id":"7dc8ab891785b022","repo":"apache/beam","slug":"t-isn-t-a-supported-encoder-function-type-passed-with-v","errorCode":null,"errorMessage":"%T isn't a supported encoder function type (passed with %v)","messagePattern":"%T isn't a supported encoder function type \\(passed with (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/row_encoder.go","lineNumber":51,"sourceCode":"\t// destination structs will be silently ignored when decoding.\n\t// This has no effect on types with registered decoder providers.\n\tRequireAllFieldsExported bool\n}\n\ntype encoderProvider = func(reflect.Type) (func(any, io.Writer) error, error)\n\n// Register accepts a provider for the given type to schema encode values of that type.\n//\n// When generating encoding functions, this builder will first check for exact type\n// matches, then against interfaces with registered factories in recency order of\n// registration, and then finally use the default Beam Schema encoding behavior.\n//\n// TODO(BEAM-9615): Add final factory types. This interface is subject to change.\n// Currently f must be a function of the type func(reflect.Type) func(T, io.Writer) (error).\nfunc (b *RowEncoderBuilder) Register(rt reflect.Type, f any) {\n\tfe, ok := f.(encoderProvider)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"%T isn't a supported encoder function type (passed with %v)\", f, rt))\n\t}\n\n\tif rt.Kind() == reflect.Interface && rt.NumMethod() == 0 {\n\t\tpanic(fmt.Sprintf(\"interface type %v must have methods\", rt))\n\t}\n\tif b.allFuncs == nil {\n\t\tb.allFuncs = make(map[reflect.Type]encoderProvider)\n\t}\n\tb.allFuncs[rt] = fe\n\tif rt.Kind() == reflect.Interface {\n\t\tb.ifaceFuncs = append(b.ifaceFuncs, rt)\n\t}\n}\n\n// Build constructs a Beam Schema coder for the given type, using any providers registered for\n// itself or it's fields.\nfunc (b *RowEncoderBuilder) Build(rt reflect.Type) (func(any, io.Writer) error, error) {\n\tif err := rowTypeValidation(rt, true); err != nil {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/row_encoder.go#L33-L69","documentation":"RowEncoderBuilder.Register panics when f is not an encoderProvider, i.e. not the expected func(reflect.Type) func(T, io.Writer) (error) factory shape. The builder stores custom encoder factories keyed by reflect.Type and requires this exact factory signature.","triggerScenarios":"Calling row_encoder_builder.Register(rt, f) where f is a plain encode function func(T, io.Writer) error instead of a provider factory, a method value, or another non-matching function type.","commonSituations":"Passing a direct encoder written against an older Beam API; confusing Register's factory signature with the per-instance encoder signature; migrating code between Beam versions where provider types changed.","solutions":["Change f to the encoderProvider factory shape func(reflect.Type) func(T, io.Writer) error","Wrap the existing encoder in a factory closure matching encoderProvider","Check the installed Beam version's encoderProvider definition"],"exampleFix":"// before\nb.Register(reflect.TypeOf(Foo{}), func(f Foo, w io.Writer) error { ... })\n// after\nb.Register(reflect.TypeOf(Foo{}), func(rt reflect.Type) func(Foo, io.Writer) error {\n\treturn func(f Foo, w io.Writer) error { ... }\n})","handlingStrategy":"validation","validationCode":"// compile-time shape check against encoderProvider\nvar _ rowcoder.EncoderProvider = myEncoderProviderFunc","typeGuard":"if _, ok := f.(encoderProvider); !ok {\n\treturn fmt.Errorf(\"f must be an encoderProvider factory\")\n}","tryCatchPattern":"func safeRegister(b *rowcoder.RowEncoderBuilder, rt reflect.Type, f any) (err error) {\n\tdefer func() { if r := recover(); r != nil { err = fmt.Errorf(\"register encoder: %v\", r) } }()\n\tb.Register(rt, f)\n\treturn nil\n}","preventionTips":["Wrap plain encoders in a factory closure matching encoderProvider","Add a compile-time assertion that your function satisfies encoderProvider","Re-check the signature after upgrading Beam versions"],"tags":["go","beam","reflection","type-mismatch"],"backgroundTag":"type-mismatch","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"}