{"record":{"id":"941088c49ba6fdb3","repo":"cayleygraph/cayley","slug":"array-fields-are-not-supported-yet","errorCode":null,"errorMessage":"array fields are not supported yet","messagePattern":"array fields are not supported yet","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/schema.go","lineNumber":209,"sourceCode":"\t\t}\n\t}\n\tif ps == \"\" {\n\t\treturn nil, fmt.Errorf(\"wrong quad format: '%s': no predicate\", rule)\n\t}\n\tp := c.toIRI(ps)\n\tif vs == \"\" || vs == any && fld.Type != reflEmptyStruct {\n\t\treturn saveRule{Pred: p, Rev: rev, Opt: opt}, nil\n\t}\n\treturn constraintRule{Pred: p, Val: c.toIRI(vs), Rev: rev}, nil\n}\n\nfunc checkFieldType(ftp reflect.Type) error {\n\tfor ftp.Kind() == reflect.Ptr || ftp.Kind() == reflect.Slice {\n\t\tftp = ftp.Elem()\n\t}\n\tswitch ftp.Kind() {\n\tcase reflect.Array: // TODO: support arrays\n\t\treturn fmt.Errorf(\"array fields are not supported yet\")\n\tcase reflect.Func, reflect.Invalid:\n\t\treturn fmt.Errorf(\"%v fields are not supported\", ftp.Kind())\n\tdefault:\n\t}\n\treturn nil\n}\n\nvar (\n\ttypesMu   sync.RWMutex\n\ttypeToIRI = make(map[reflect.Type]quad.IRI)\n\tiriToType = make(map[quad.IRI]reflect.Type)\n)\n\nfunc getTypeIRI(rt reflect.Type) quad.IRI {\n\ttypesMu.RLock()\n\tiri := typeToIRI[rt]\n\ttypesMu.RUnlock()\n\treturn iri","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/schema.go#L191-L227","documentation":"Schema generation walks struct fields via reflection and only supports pointer/slice-wrapped scalars and structs. Fixed-size arrays (reflect.Array) are explicitly unsupported, so Generate fails when it encounters one. There is a TODO in the source to add array support.","triggerScenarios":"Calling Generate on a struct that contains a field of type [N]T, e.g. [4]byte or [2]string.","commonSituations":"Models with fixed-size binary hashes, coordinate tuples, or fixed buffers declared as arrays instead of slices.","solutions":["Change the field to a slice ([]T) instead of a fixed array","Exclude the field from schema with the appropriate ignore tag (e.g. `quad:\"-\"`)","Convert the array to a supported type before calling Generate, or wrap it in a custom struct"],"exampleFix":"// before\ntype Doc struct {\n    Hash [32]byte\n}\n// after\ntype Doc struct {\n    Hash []byte\n}","handlingStrategy":"validation","validationCode":"func hasArrayField(v interface{}) bool {\n    t := reflect.TypeOf(v)\n    if t.Kind() == reflect.Ptr { t = t.Elem() }\n    for i := 0; i < t.NumField(); i++ {\n        ft := t.Field(i).Type\n        for ft.Kind() == reflect.Ptr || ft.Kind() == reflect.Slice { ft = ft.Elem() }\n        if ft.Kind() == reflect.Array { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"if err := schema.Generate(c, Person{}); err != nil {\n    if strings.Contains(err.Error(), \"array fields are not supported\") {\n        // convert field to slice or ignore it\n    }\n    return err\n}","preventionTips":["Use slices instead of fixed-size arrays in schema-mapped structs","Tag unsupported fields with the ignore tag","Run Generate for all types in an init/test to catch this early"],"tags":["schema","reflection","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}