{"record":{"id":"8faa005b2cae714e","repo":"cayleygraph/cayley","slug":"can-t-load-rules-v","errorCode":null,"errorMessage":"can't load rules: %v","messagePattern":"can't load rules: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/namespaces.go","lineNumber":23,"sourceCode":"\t\"fmt\"\n\t\"reflect\"\n\n\t\"github.com/cayleygraph/cayley/graph\"\n\t\"github.com/cayleygraph/quad\"\n\t\"github.com/cayleygraph/quad/voc\"\n)\n\ntype namespace struct {\n\t_      struct{} `quad:\"@type > cayley:namespace\"`\n\tFull   quad.IRI `quad:\"@id\"`\n\tPrefix quad.IRI `quad:\"cayley:prefix\"`\n}\n\n// WriteNamespaces will writes namespaces list into graph.\nfunc (c *Config) WriteNamespaces(w quad.Writer, n *voc.Namespaces) error {\n\trules, err := c.rulesFor(reflect.TypeOf(namespace{}))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't load rules: %v\", err)\n\t}\n\twr := c.newWriter(w)\n\tfor _, ns := range n.List() {\n\t\tobj := namespace{\n\t\t\tFull:   quad.IRI(ns.Full),\n\t\t\tPrefix: quad.IRI(ns.Prefix),\n\t\t}\n\t\trv := reflect.ValueOf(obj)\n\t\tif err = wr.writeValueAs(obj.Full, rv, \"\", rules); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\n// LoadNamespaces will load namespaces stored in graph to a specified list.\n// If destination list is empty, global namespace registry will be used.\nfunc (c *Config) LoadNamespaces(ctx context.Context, qs graph.QuadStore, dest *voc.Namespaces) error {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/namespaces.go#L5-L41","documentation":"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\".","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nc.AddType(scheme, \"iri:\") // malformed rule\n// after\nc.AddType(scheme, \"iri\") // valid rule format","handlingStrategy":"try-catch","validationCode":"if err := c.WriteNamespaces(w, n); err != nil {\n    if strings.HasPrefix(err.Error(), \"can't load rules\") {\n        // inspect inner error; rebuild schema config\n    }\n    return err\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil { /* reset config state */ }\n}()\nif err := c.WriteNamespaces(w, n); err != nil {\n    return fmt.Errorf(\"namespace write: %w\", err)\n}","preventionTips":["Keep AddType/RegisterConverter rules well-formed.","Write integration tests that call WriteNamespaces on a fresh Config.","Avoid mutating the Config concurrently with writes."],"tags":["go","schema","namespaces"],"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-14T05:17:10.506Z"}