{"record":{"id":"cec22f9f976fce18","repo":"apache/beam","slug":"cannot-convert-v-to-schema-fromtype-only-converts-structs-to","errorCode":null,"errorMessage":"cannot convert %v to schema. FromType only converts structs to schemas","messagePattern":"cannot convert (.+?) to schema\\. FromType only converts structs to schemas","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go","lineNumber":325,"sourceCode":"\t// empty types have no value for lookups.\n\tif synth != emptyStructType {\n\t\tr.syntheticToUser[synth] = ut\n\t\tr.syntheticToUser[reflect.PtrTo(synth)] = reflect.PtrTo(ut)\n\t}\n\tif ut != emptyStructType {\n\t\tr.syntheticToUser[ut] = ut\n\t\tr.syntheticToUser[reflect.PtrTo(ut)] = reflect.PtrTo(ut)\n\t}\n}\n\n// FromType returns a Beam Schema of the passed in type.\n// Returns an error if the type cannot be converted to a Schema.\nfunc (r *Registry) FromType(ot reflect.Type) (*pipepb.Schema, error) {\n\tif err := r.reconcileRegistrations(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"reconciling for FromType\")\n\t}\n\tif reflectx.SkipPtr(ot).Kind() != reflect.Struct {\n\t\treturn nil, errors.Errorf(\"cannot convert %v to schema. FromType only converts structs to schemas\", ot)\n\t}\n\treturn r.fromType(ot)\n}\n\nfunc (r *Registry) logicalTypeToFieldType(t reflect.Type) (*pipepb.FieldType, string, error) {\n\t// Check if a logical type was registered that matches this struct type directly\n\t// and if so, extract the schema from it for use.\n\tif lID, ok := r.logicalTypeIdentifiers[t]; ok {\n\t\tlt := r.logicalTypes[lID]\n\t\tftype, err := r.reflectTypeToFieldType(lt.StorageType())\n\t\tif err != nil {\n\t\t\treturn nil, \"\", errors.Wrapf(err, \"unable to convert LogicalType[%v]'s storage type %v for Go type of %v to a schema\", lID, lt.StorageType(), lt.GoType())\n\t\t}\n\t\treturn ftype, lID, nil\n\t}\n\tfor _, lti := range r.logicalTypeInterfaces {\n\t\tif !t.Implements(lti) {\n\t\t\tcontinue","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go#L307-L343","documentation":"FromType only converts Go struct types into Beam Row schemas. If the passed reflect.Type (after skipping pointers) is not of Kind reflect.Struct, this error is returned directly. It signals API misuse: FromType is the wrong entry point for non-struct types.","triggerScenarios":"Calling Registry.FromType(reflect.TypeOf(x)) where x is a slice, map, string, int, or other non-struct (pointers are skipped, so the pointed-to kind is what matters).","commonSituations":"Trying to schema-encode a []byte, map, or primitive; accidentally passing reflect.TypeOf on a slice variable; converting wrapper types instead of their row structs.","solutions":["Pass a struct type (or pointer to struct) to FromType.","Wrap non-struct leaf types in a struct field or register a LogicalType via RegisterLogicalType.","Assert before calling: reflectx.SkipPtr(t).Kind() == reflect.Struct."],"exampleFix":"// before\nt := reflect.TypeOf([]string{})\nschm, err := reg.FromType(t) // error\n// after\ntype Rows struct { Values []string }\nschm, err := reg.FromType(reflect.TypeOf(Rows{}))","handlingStrategy":"type-guard","validationCode":"t := reflect.TypeOf(x)\nif reflectx.SkipPtr(t).Kind() != reflect.Struct {\n    return nil, fmt.Errorf(\"%v is not a struct; FromType requires structs\", t)\n}","typeGuard":"func isSchemaConvertibleStruct(v interface{}) bool {\n    return reflectx.SkipPtr(reflect.TypeOf(v)).Kind() == reflect.Struct\n}","tryCatchPattern":"schm, err := reg.FromType(t)\nif err != nil && strings.Contains(err.Error(), \"only converts structs\") {\n    return nil, fmt.Errorf(\"wrap %v in a struct or register a logical type\", t)\n}","preventionTips":["Only pass struct types (or pointers to structs) to FromType.","Wrap primitives/maps in a row struct before conversion.","Guard with reflectx.SkipPtr(t).Kind() == reflect.Struct before calling.","Use RegisterLogicalType for non-struct leaf types."],"tags":["go","schema","invalid-argument","reflection"],"backgroundTag":"invalid-argument-value","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"}