{"record":{"id":"27759a012b1f8163","repo":"apache/beam","slug":"cannot-make-schema-encoder-for-type-v-as-it-has-an-embedded","errorCode":null,"errorMessage":"cannot make schema encoder for type %v as it has an embedded field of a pointer to an unexported type %v. See https://golang.org/issue/21357","messagePattern":"cannot make schema encoder for type (.+?) as it has an embedded field of a pointer to an unexported type (.+?)\\. See https://golang\\.org/issue/21357","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/row_encoder.go","lineNumber":306,"sourceCode":"\tvar coder typeEncoderReflect\n\tfor i := 0; i < t.NumField(); i++ {\n\t\tcoder.debug = append(coder.debug, t.Field(i).Name+\" \"+t.Field(i).Type.String())\n\t\tsf := t.Field(i)\n\t\tisUnexported := sf.PkgPath != \"\"\n\t\tif sf.Anonymous {\n\t\t\tft := sf.Type\n\t\t\tif ft.Kind() == reflect.Ptr {\n\t\t\t\t// If a struct embeds a pointer to an unexported type,\n\t\t\t\t// it is not possible to set a newly allocated value\n\t\t\t\t// since the field is unexported.\n\t\t\t\t//\n\t\t\t\t// See https://golang.org/issue/21357\n\t\t\t\t//\n\t\t\t\t// Since the values are created by this package reflectively,\n\t\t\t\t// there's no work around like pre-allocating the field\n\t\t\t\t// manually.\n\t\t\t\tif isUnexported {\n\t\t\t\t\treturn nil, errors.Errorf(\"cannot make schema encoder for type %v as it has an embedded field of a pointer to an unexported type %v. See https://golang.org/issue/21357\", t, ft.Elem())\n\t\t\t\t}\n\t\t\t\tft = ft.Elem()\n\t\t\t}\n\t\t\tif isUnexported && ft.Kind() != reflect.Struct {\n\t\t\t\t// Ignore embedded fields of unexported non-struct types.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// Do not ignore embedded fields of unexported struct types\n\t\t\t// since they may have exported fields.\n\t\t} else if isUnexported {\n\t\t\tif b.RequireAllFieldsExported {\n\t\t\t\treturn nil, errors.Errorf(\"cannot make schema encoder for type %v as it has unexported fields such as %s.\", t, sf.Name)\n\t\t\t}\n\t\t\t// Silently ignore, since we can't do anything about it.\n\t\t\t// Add a no-op coder to fill in field index\n\t\t\tcoder.fields = append(coder.fields, typeEncoderFieldReflect{encode: func(rv reflect.Value, w io.Writer) error {\n\t\t\t\treturn nil\n\t\t\t}})","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/row_encoder.go#L288-L324","documentation":"Beam cannot build a schema encoder for a struct with an embedded pointer to an unexported type, because reflect cannot safely construct that embedded value (golang.org/issue/21357). The encoder refuses rather than produce broken encodings.","triggerScenarios":"Encoding a struct that embeds *unexportedType, e.g. type T struct { *foo }; passing T (or a struct containing it) to reflective schema row encoding.","commonSituations":"Internal-ish embedded pointer types (common with generated or package-private base types) surfacing in PCollection elements.","solutions":["Remove the embedded pointer to the unexported type; embed an exported type instead","Flatten the embedded fields into the struct explicitly","Use a custom coder instead of reflective schema coding for this type"],"exampleFix":"// before\ntype Wrapper struct { *base }\n// after\ntype Wrapper struct { Base } // where Base is exported","handlingStrategy":"validation","validationCode":"func hasEmbeddedUnexportedPtr(t reflect.Type) bool {\n    if t.Kind() != reflect.Struct { return false }\n    for i := 0; i < t.NumField(); i++ {\n        f := t.Field(i)\n        if f.Anonymous && f.Type.Kind() == reflect.Ptr && !f.Type.Elem().IsExported() {\n            return true\n        }\n    }\n    return false\n}","typeGuard":"func isSchemaEncodableStruct(t reflect.Type) bool { return !hasEmbeddedUnexportedPtr(t) }","tryCatchPattern":"if _, err := (coder.RowEncoderBuilder{}).Build(t); err != nil {\n    return fmt.Errorf(\"struct %s not schema-encodable: %w\", t, err)\n}","preventionTips":["Never embed pointers to unexported types in pipeline element structs","Prefer exported embedded structs","Run schema-coder build checks as part of unit tests"],"tags":["go","beam","reflection","struct","encoder"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}