{"record":{"id":"b3a714353288a5ee","repo":"MyCATApache/Mycat-Server","slug":"rule-rulename-is-not-found","errorCode":null,"errorMessage":"rule ${ruleName} is not found!","messagePattern":"rule (.+?) is not found!","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java","lineNumber":367,"sourceCode":"            //记录是否需要加返回结果集限制，默认需要加\n            boolean needAddLimit = true;\n            if (tableElement.hasAttribute(\"needAddLimit\")) {\n                needAddLimit = Boolean.parseBoolean(tableElement.getAttribute(\"needAddLimit\"));\n            }\n            //记录type，是否为global\n            String tableTypeStr = tableElement.hasAttribute(\"type\") ? tableElement.getAttribute(\"type\") : null;\n            int tableType = TableConfig.TYPE_GLOBAL_DEFAULT;\n            if (\"global\".equalsIgnoreCase(tableTypeStr)) {\n                tableType = TableConfig.TYPE_GLOBAL_TABLE;\n            }\n            //记录dataNode，就是分布在哪些dataNode上\n            String dataNode = tableElement.getAttribute(\"dataNode\");\n            TableRuleConfig tableRule = null;\n            if (tableElement.hasAttribute(\"rule\")) {\n                String ruleName = tableElement.getAttribute(\"rule\");\n                tableRule = tableRules.get(ruleName);\n                if (tableRule == null) {\n                    throw new ConfigException(\"rule \" + ruleName + \" is not found!\");\n                }\n            }\n\n            boolean ruleRequired = false;\n            //记录是否绑定有分片规则\n            if (tableElement.hasAttribute(\"ruleRequired\")) {\n                ruleRequired = Boolean.parseBoolean(tableElement.getAttribute(\"ruleRequired\"));\n            }\n\n            if (tableNames == null) {\n                throw new ConfigException(\"table name is not found!\");\n            }\n            //distribute函数，重新编排dataNode\n            String distPrex = \"distribute(\";\n            boolean distTableDns = dataNode.startsWith(distPrex);\n            if (distTableDns) {\n                dataNode = dataNode.substring(distPrex.length(), dataNode.length() - 1);\n            }","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java#L349-L385","documentation":"Thrown by XMLSchemaLoader.loadTable when a <table> element declares a 'rule' attribute whose value does not match any <tableRule name=\"...\"> defined in the schema XML. Mycat resolves table sharding rules by name from the tableRules map built earlier; an unresolvable rule name means the table has no valid partitioning strategy, so startup aborts with ConfigException.","triggerScenarios":"A <table name=\"t\" rule=\"ruleX\"> entry in schema.xml where 'ruleX' is not defined as a <tableRule name=\"ruleX\"> in rule.xml, or the rule name is misspelled/renamed while tables still reference the old name.","commonSituations":"Typo in the rule attribute; rule defined in rule.xml but schema.xml references a stale name after a refactor; copy-pasting table configs from another project with different rule names; rule declared after use in a merged config.","solutions":["Check rule.xml for a <tableRule name=\"...\"> whose name exactly matches the table's rule attribute","Fix the spelling of the rule attribute in the <table> element in schema.xml","Add the missing <tableRule> definition to rule.xml","If the table needs no sharding, remove the rule attribute entirely (optionally set ruleRequired=\"false\")"],"exampleFix":"// before (schema.xml)\n<table name=\"orders\" dataNode=\"dn1\" rule=\"ordrRule\" />\n// after\n<table name=\"orders\" dataNode=\"dn1\" rule=\"orderRule\" /> <!-- matches <tableRule name=\"orderRule\"> in rule.xml -->","handlingStrategy":"validation","validationCode":"// before starting Mycat, verify every table rule reference exists\nSet<String> definedRules = collectTableRuleNames(\"rule.xml\");\nfor (Element t : schemaTables(\"schema.xml\")) {\n    if (t.hasAttribute(\"rule\") && !definedRules.contains(t.getAttribute(\"rule\")))\n        throw new IllegalStateException(\"Undefined rule: \" + t.getAttribute(\"rule\"));\n}","typeGuard":null,"tryCatchPattern":"try {\n    configLoader.load();\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"is not found\") && e.getMessage().startsWith(\"rule\")) {\n        log.error(\"Fix schema.xml <table rule=...> to match a <tableRule name=...> in rule.xml\", e);\n    }\n    throw e; // config errors are fatal, do not swallow\n}","preventionTips":["Keep rule names in schema.xml and rule.xml in sync; diff them in CI","Grep schema.xml rule attributes against rule.xml tableRule names at build time","Never rename a tableRule without updating all referencing tables"],"tags":["config","sharding","xml","missing-reference"],"backgroundTag":"resource-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}