{"record":{"id":"90d0377453a3633e","repo":"cayleygraph/cayley","slug":"can-t-load-rules-v-90d037","errorCode":null,"errorMessage":"can't load rules: %v","messagePattern":"can't load rules: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/writer.go","lineNumber":160,"sourceCode":"\t\treturn quad.String(rv.String()), nil\n\t} else if kind == reflect.Int || kind == reflect.Uint ||\n\t\tkind == reflect.Int32 || kind == reflect.Uint32 ||\n\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}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/schema/writer.go#L142-L178","documentation":"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.","triggerScenarios":"Writing a struct whose schema generation fails - e.g. a func-typed field, unsupported embedded field, or a malformed quad-format tag string.","commonSituations":"First write of a newly added struct with invalid `tag:\"...\"` annotations; refactoring a struct to add callbacks or embedded primitives then writing it.","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"],"exampleFix":"// before\ntype Doc struct {\n    Fn func() `tag:\"fn\"`\n}\n// after\ntype Doc struct {\n    Name string `tag:\"name\"`\n}","handlingStrategy":"try-catch","validationCode":"if err := schema.Generate(cfg, Doc{}); err != nil {\n    return fmt.Errorf(\"schema invalid before write: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := w.WriteAsQuads(qs, doc); err != nil {\n    var wrapped string = err.Error()\n    if strings.Contains(wrapped, \"can't load rules\") {\n        log.Printf(\"fix struct schema: %v\", wrapped) // inner cause included\n        return err\n    }\n    return err\n}","preventionTips":["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"],"tags":["schema","serialization","configuration"],"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"}