{"record":{"id":"c25aaf9206f6a6c3","repo":"cayleygraph/cayley","slug":"no-rules-for-struct-v","errorCode":null,"errorMessage":"no rules for struct: %v","messagePattern":"no rules for struct: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/writer.go","lineNumber":163,"sourceCode":"\t\tkind == reflect.Int16 || kind == reflect.Uint16 ||\n\t\tkind == reflect.Int8 || kind == reflect.Uint8 {\n\t\treturn quad.Int(rv.Int()), nil\n\t} else if kind == reflect.Float64 || kind == reflect.Float32 {\n\t\treturn quad.Float(rv.Float()), nil\n\t} else if kind == reflect.Bool {\n\t\treturn quad.Bool(rv.Bool()), nil\n\t}\n\t// TODO(dennwc): support maps\n\tif kind != reflect.Struct {\n\t\treturn nil, fmt.Errorf(\"unsupported type: %v\", rt)\n\t}\n\t// get conversion rules for this struct type\n\trules, err := w.c.rulesFor(rt)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"can't load rules: %v\", err)\n\t}\n\tif len(rules) == 0 {\n\t\treturn nil, fmt.Errorf(\"no rules for struct: %v\", rt)\n\t}\n\t// get an ID from the struct value\n\tid, err := w.c.idFor(rules, rt, rv, \"\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif id == nil {\n\t\tid = w.c.genID(prv.Interface())\n\t}\n\t// save a node ID to avoid loops\n\tswitch prv.Kind() {\n\tcase reflect.Ptr, reflect.Map:\n\t\tptr := prv.Pointer()\n\t\tw.seen[ptr] = id\n\t}\n\tif err = w.writeValueAs(id, rv, \"\", rules); err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/writer.go#L145-L181","documentation":"After loading rules, writeAsQuads checks that the struct actually produced field rules. An empty rule set means the struct has no mapped fields (all ignored or no usable tags), so there is nothing to serialize into quads. The error names the offending struct type.","triggerScenarios":"Writing a struct whose every field is excluded from schema mapping (e.g. all tagged `quad:\"-\"`) or which contains only unsupported/ignored fields.","commonSituations":"Marker/empty structs accidentally passed to the writer; over-aggressive ignore tags after refactoring; structs relying solely on fields the generator skips.","solutions":["Add at least one mapped field with a valid schema tag to the struct","Review ignore tags - remove `quad:\"-\"` from fields that should be stored","Skip writing structs that intentionally carry no data, or handle them with raw quads instead"],"exampleFix":"// before\ntype Doc struct {\n    Internal string `quad:\"-\"`\n}\n// after\ntype Doc struct {\n    Internal string `quad:\"-\"`\n    Name     string `tag:\"name\"`\n}","handlingStrategy":"validation","validationCode":"rules, err := cfg.RulesFor(reflect.TypeOf(doc))\nif err != nil { return err }\nif len(rules) == 0 {\n    return fmt.Errorf(\"struct %T has no schema-mapped fields\", doc)\n}","typeGuard":null,"tryCatchPattern":"if _, err := w.WriteAsQuads(qs, doc); err != nil {\n    if strings.Contains(err.Error(), \"no rules for struct\") {\n        // ensure the struct has at least one tagged, supported field\n        return err\n    }\n    return err\n}","preventionTips":["Ensure every persisted struct has at least one non-ignored mapped field","Audit ignore tags after refactoring","Assert non-empty rules per type in a startup validation routine"],"tags":["schema","serialization","empty-mapping"],"backgroundTag":"schema-validation-failed","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"}