{"record":{"id":"a6ac92d9d3228d53","repo":"apache/beam","slug":"type-v-must-be-a-named-type-not-anonymous-for-registration","errorCode":null,"errorMessage":"type %v must be a named type (not anonymous) for registration","messagePattern":"type (.+?) must be a named type \\(not anonymous\\) for registration","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sdks/go/pkg/beam/io/bigqueryio/bigquery.go","lineNumber":238,"sourceCode":"func mustInferSchema(t reflect.Type) bigquery.Schema {\n\tif t.Kind() != reflect.Struct {\n\t\tpanic(fmt.Sprintf(\"schema type must be struct: %v\", t))\n\t}\n\n\tcheckTypeRegistered(t)\n\n\tschema, err := bigquery.InferSchema(reflect.Zero(t).Interface())\n\tif err != nil {\n\t\tpanic(errors.Wrapf(err, \"invalid schema type: %v\", t))\n\t}\n\treturn schema\n}\n\nfunc checkTypeRegistered(t reflect.Type) {\n\tt = reflectx.SkipPtr(t)\n\tkey, ok := runtime.TypeKey(t)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"type %v must be a named type (not anonymous) for registration\", t))\n\t}\n\n\tif _, registered := runtime.LookupType(key); !registered {\n\t\tpanic(fmt.Sprintf(\"type %v is not registered. Ensure that beam.RegisterType(%v) \"+\n\t\t\t\"is called before beam.Init().\", t, t))\n\t}\n}\n\nfunc mustParseTable(table string) QualifiedTableName {\n\tqn, err := NewQualifiedTableName(table)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn qn\n}\n\n// TODO(herohde) 7/14/2017: allow WriteDispositions. The default\n// is not quite what the Dataflow examples do.","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/bigqueryio/bigquery.go#L220-L256","documentation":"checkTypeRegistered panics when the struct type used for BigQuery schema inference is an anonymous type (unnamed struct literal type, e.g. from an inline struct or reflection-created type). The Beam runtime requires a stable, named type key for serialization and type registration, and runtime.TypeKey returns ok=false for anonymous types.","triggerScenarios":"Using an anonymous struct in bigqueryio.Read/Write, e.g. beam.Create(s, struct{ Name string }{\"x\"}) or a PCollection whose element type is an unnamed struct{} literal type rather than a declared named type.","commonSituations":"Declaring rows inline inside beam.Create or a DoFn's emit without naming the type; generating struct types dynamically with reflect.StructOf; test code with ad-hoc anonymous structs.","solutions":["Declare a named Go type (type MyRow struct {...}) and use it as the PCollection element type.","Replace anonymous inline structs passed to beam.Create with instances of a package-level named struct.","If the type comes from a third-party package, wrap it in your own named struct."],"exampleFix":"// before\nbigqueryio.Write(s, proj, ds, table, beam.Create(s, struct{ N int }{1}))\n\n// after\ntype MyRow struct {\n    N int `bigquery:\"n\"`\n}\nbigqueryio.Write(s, proj, ds, table, beam.Create(s, MyRow{N: 1}))","handlingStrategy":"validation","validationCode":"t := reflectx.SkipPtr(col.Type().Type())\nif t.Name() == \"\" {\n    return fmt.Errorf(\"element type %v must be a named type\", t)\n}","typeGuard":"func isNamedType(t reflect.Type) bool {\n    return t.Name() != \"\"\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"type registration check failed: %v\", r)\n    }\n}()","preventionTips":["Never use anonymous structs as PCollection element types.","Declare row types at package level with clear names.","Avoid reflect.StructOf for pipeline element types."],"tags":["go","bigquery","panic","anonymous-type"],"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"}