cayleygraph/cayley · error
can't load rules: %v
Error message
can't load rules: %v
What it means
writeAsQuads asks the Config for conversion rules via rulesFor(rt), which runs full schema generation for the struct type. Any error during generation (bad tags, unsupported fields, anonymous fields) is wrapped as "can't load rules". The root cause is always an inner schema-generation failure reported in the wrapped message.
Source
Thrown at schema/writer.go:160
return quad.String(rv.String()), nil
} else if kind == reflect.Int || kind == reflect.Uint ||
kind == reflect.Int32 || kind == reflect.Uint32 ||
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
}View on GitHub (pinned to 81dcd7d73e)
Solutions
- Read the wrapped inner error to find the exact offending field/rule
- Call Generate once at startup for all schema structs so errors surface early
- Fix the invalid struct tag or unsupported field identified in the wrapped message
Example fix
// before
type Doc struct {
Fn func() `tag:"fn"`
}
// after
type Doc struct {
Name string `tag:"name"`
} Defensive patterns
Strategy: try-catch
Validate before calling
if err := schema.Generate(cfg, Doc{}); err != nil {
return fmt.Errorf("schema invalid before write: %w", err)
} Try / catch
if _, err := w.WriteAsQuads(qs, doc); err != nil {
var wrapped string = err.Error()
if strings.Contains(wrapped, "can't load rules") {
log.Printf("fix struct schema: %v", wrapped) // inner cause included
return err
}
return err
} Prevention
- Call schema.Generate for every mapped struct at application startup
- Keep struct tags minimal and validated; test tag parsing in CI
- Never add func/embedded-primitive fields to persisted structs
When it happens
Trigger: Writing a struct whose schema generation fails - e.g. a func-typed field, unsupported embedded field, or a malformed quad-format tag string.
Common situations: First write of a newly added struct with invalid `tag:"..."` annotations; refactoring a struct to add callbacks or embedded primitives then writing it.
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
- wrong quad format: '%s': no predicate
- unsupported type: %v
- no rules for struct: %v
- HTTP Request needed
- ErrEmptyPath
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/90d0377453a3633e.
Report an issue: GitHub.