{"record":{"id":"60e7b8f45c1e3038","repo":"apache/beam","slug":"cannot-make-schema-for-type-v-as-it-has-an-embedded-field-of","errorCode":null,"errorMessage":"cannot make schema 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 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/runtime/graphx/schema/schema.go","lineNumber":181,"sourceCode":"\t}\n\treturn false\n}\n\nfunc ignoreField(t reflect.Type, sf reflect.StructField) (ignore, isAnon bool, err error) {\n\tisUnexported := sf.PkgPath != \"\"\n\tif sf.Anonymous {\n\t\tft := sf.Type\n\t\tif ft.Kind() == reflect.Ptr {\n\t\t\t// If a struct embeds a pointer to an unexported type,\n\t\t\t// it is not possible to set a newly allocated value\n\t\t\t// since the field is unexported.\n\t\t\t//\n\t\t\t// See https://golang.org/issue/21357\n\t\t\t//\n\t\t\t// Since the values are created by the decoder reflectively,\n\t\t\t// fail early here.\n\t\t\tif isUnexported {\n\t\t\t\treturn false, false, errors.Errorf(\"cannot make schema 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}\n\t\t\tft = ft.Elem()\n\t\t}\n\t\tif isUnexported && ft.Kind() != reflect.Struct {\n\t\t\t// Ignore embedded fields of unexported non-struct types.\n\t\t\treturn true, true, nil\n\t\t}\n\t\t// Do not ignore embedded fields of unexported struct types\n\t\t// since they may have exported fields.\n\t\treturn false, true, nil\n\t}\n\tif isUnexported {\n\t\t// Schemas can't handle unexported fields at all.\n\t\treturn true, false, nil\n\t}\n\tif implements(sf.Type, sdfRtrackerType) {\n\t\t// ignoring sdf.Rtracker interface\n\t\treturn true, false, nil","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go#L163-L199","documentation":"When converting a Go struct into a schema, ignoreField rejects structs containing an embedded field that is a pointer to an unexported type. Because the schema decoder creates values reflectively, it cannot construct such fields (golang/go#21357), so registration fails early with this message.","triggerScenarios":"registerType or structToSchema walks a struct type that embeds, e.g. `*privateType` where privateType is unexported, while generating the schema.","commonSituations":"Pipelines whose DoFns emit structs embedding pointers to unexported types (common with generated or package-private helper types); passing such types to beam.RowEncoder/schema conversion.","solutions":["Export the embedded type or embed a value/exported pointer instead of a pointer to an unexported type.","Register an explicit custom coder for the outer type so schema conversion is bypassed.","Flatten the needed fields of the unexported type into exported fields of the outer struct."],"exampleFix":"// before\ntype Result struct { *config } // config is unexported\n// after\ntype Result struct { Config *Config } // Config exported","handlingStrategy":"validation","validationCode":"func hasUnexportedEmbeddedPtr(t reflect.Type) bool {\n    for i := 0; i < t.NumField(); i++ {\n        f := t.Field(i)\n        if f.Anonymous && f.Type.Kind() == reflect.Ptr {\n            return !f.Type.Elem().IsExported == nil // elem type unexported\n        }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"pointer to an unexported type\") {\n        // restructure the type or register a custom coder\n    }\n}","preventionTips":["Never embed pointers to unexported types in pipeline data structs","Run schema conversion checks in CI on all emitted types","Flatten unexported helper types into exported fields"],"tags":["go","beam","schema","reflection","embedded-fields"],"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"}