cayleygraph/cayley · error
can't load rules: %v
Error message
can't load rules: %v
What it means
WriteNamespaces derives the schema rules for the internal namespace struct via rulesFor before writing the namespace list into the graph. If rulesFor returns an error (malformed quad tags or field setup), it is wrapped as "can't load rules: %v".
Source
Thrown at schema/namespaces.go:23
"fmt"
"reflect"
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/quad"
"github.com/cayleygraph/quad/voc"
)
type namespace struct {
_ struct{} `quad:"@type > cayley:namespace"`
Full quad.IRI `quad:"@id"`
Prefix quad.IRI `quad:"cayley:prefix"`
}
// WriteNamespaces will writes namespaces list into graph.
func (c *Config) WriteNamespaces(w quad.Writer, n *voc.Namespaces) error {
rules, err := c.rulesFor(reflect.TypeOf(namespace{}))
if err != nil {
return fmt.Errorf("can't load rules: %v", err)
}
wr := c.newWriter(w)
for _, ns := range n.List() {
obj := namespace{
Full: quad.IRI(ns.Full),
Prefix: quad.IRI(ns.Prefix),
}
rv := reflect.ValueOf(obj)
if err = wr.writeValueAs(obj.Full, rv, "", rules); err != nil {
return err
}
}
return nil
}
// LoadNamespaces will load namespaces stored in graph to a specified list.
// If destination list is empty, global namespace registry will be used.
func (c *Config) LoadNamespaces(ctx context.Context, qs graph.QuadStore, dest *voc.Namespaces) error {View on GitHub (pinned to 81dcd7d73e)
Solutions
- Read the wrapped inner error to identify the offending rule or field.
- Re-check all Config.AddType / RegisterConverter calls for malformed quad tag rules.
- Reset to a fresh schema.Config and re-register types to isolate the bad registration.
Example fix
// before c.AddType(scheme, "iri:") // malformed rule // after c.AddType(scheme, "iri") // valid rule format
Defensive patterns
Strategy: try-catch
Validate before calling
if err := c.WriteNamespaces(w, n); err != nil {
if strings.HasPrefix(err.Error(), "can't load rules") {
// inspect inner error; rebuild schema config
}
return err
} Try / catch
defer func() {
if r := recover(); r != nil { /* reset config state */ }
}()
if err := c.WriteNamespaces(w, n); err != nil {
return fmt.Errorf("namespace write: %w", err)
} Prevention
- Keep AddType/RegisterConverter rules well-formed.
- Write integration tests that call WriteNamespaces on a fresh Config.
- Avoid mutating the Config concurrently with writes.
When it happens
Trigger: Calling Config.WriteNamespaces(w quad.Writer, n *voc.Namespaces) when the schema configuration for the internal namespace type cannot be built — usually due to a bad custom type registration or corrupted Config state.
Common situations: Registering a converter/type with invalid rules that break rulesFor for the namespace struct; using a Config with misconfigured AddType mappings; bugs after upgrading the vocabulary package.
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
- not found
- required field is missing
- expected struct, got %v
- load anonymous field %s failed: %v
- field %s: %v
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/8faa005b2cae714e.
Report an issue: GitHub.