cayleygraph/cayley · error
no rules for struct: %v
Error message
no rules for struct: %v
What it means
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.
Source
Thrown at schema/writer.go:163
kind == reflect.Int16 || kind == reflect.Uint16 ||
kind == reflect.Int8 || kind == reflect.Uint8 {
return quad.Int(rv.Int()), nil
} else if kind == reflect.Float64 || kind == reflect.Float32 {
return quad.Float(rv.Float()), nil
} else if kind == reflect.Bool {
return quad.Bool(rv.Bool()), nil
}
// TODO(dennwc): support maps
if kind != reflect.Struct {
return nil, fmt.Errorf("unsupported type: %v", rt)
}
// get conversion rules for this struct type
rules, err := w.c.rulesFor(rt)
if err != nil {
return nil, fmt.Errorf("can't load rules: %v", err)
}
if len(rules) == 0 {
return nil, fmt.Errorf("no rules for struct: %v", rt)
}
// get an ID from the struct value
id, err := w.c.idFor(rules, rt, rv, "")
if err != nil {
return nil, err
}
if id == nil {
id = w.c.genID(prv.Interface())
}
// save a node ID to avoid loops
switch prv.Kind() {
case reflect.Ptr, reflect.Map:
ptr := prv.Pointer()
w.seen[ptr] = id
}
if err = w.writeValueAs(id, rv, "", rules); err != nil {
return nil, err
}View on GitHub (pinned to 81dcd7d73e)
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
Example fix
// before
type Doc struct {
Internal string `quad:"-"`
}
// after
type Doc struct {
Internal string `quad:"-"`
Name string `tag:"name"`
} Defensive patterns
Strategy: validation
Validate before calling
rules, err := cfg.RulesFor(reflect.TypeOf(doc))
if err != nil { return err }
if len(rules) == 0 {
return fmt.Errorf("struct %T has no schema-mapped fields", doc)
} Try / catch
if _, err := w.WriteAsQuads(qs, doc); err != nil {
if strings.Contains(err.Error(), "no rules for struct") {
// ensure the struct has at least one tagged, supported field
return err
}
return err
} Prevention
- 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
When it happens
Trigger: Writing a struct whose every field is excluded from schema mapping (e.g. all tagged `quad:"-"`) or which contains only unsupported/ignored fields.
Common situations: Marker/empty structs accidentally passed to the writer; over-aggressive ignore tags after refactoring; structs relying solely on fields the generator skips.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/c25aaf9206f6a6c3.
Report an issue: GitHub.