{"record":{"id":"56c059afa2ff7e00","repo":"alibaba/open-code-review","slug":"read-rule-file-q-for-pattern-q-w","errorCode":null,"errorMessage":"read rule file %q for pattern %q: %w","messagePattern":"read rule file %q for pattern %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/config/rules/system_rules.go","lineNumber":110,"sourceCode":"// LoadDefault parses the embedded system_rules.json and resolves rule file references.\nfunc LoadDefault() (*SystemRule, error) {\n\tdata, err := rulesFS.ReadFile(\"system_rules.json\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read embedded system_rules.json: %w\", err)\n\t}\n\tvar rule SystemRule\n\tif err := json.Unmarshal(data, &rule); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal default system rules: %w\", err)\n\t}\n\tcontent, err := rulesFS.ReadFile(\"rule_docs/\" + rule.DefaultRule)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read default rule file %q: %w\", rule.DefaultRule, err)\n\t}\n\trule.DefaultRule = strings.TrimRight(string(content), \"\\n\")\n\tfor i := range rule.PathRules {\n\t\tcontent, err := rulesFS.ReadFile(\"rule_docs/\" + rule.PathRules[i].Rule)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"read rule file %q for pattern %q: %w\", rule.PathRules[i].Rule, rule.PathRules[i].Pattern, err)\n\t\t}\n\t\trule.PathRules[i].Rule = strings.TrimRight(string(content), \"\\n\")\n\t}\n\treturn &rule, nil\n}\n\n// loadObjCRule reads the embedded Objective-C rule doc used by the \".m\"\n// content sniff. It is not referenced from system_rules.json's path_rule_map,\n// so it is loaded explicitly rather than through the PathRules loop.\nfunc loadObjCRule() (string, error) {\n\tcontent, err := rulesFS.ReadFile(\"rule_docs/objc.md\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read objc rule file: %w\", err)\n\t}\n\treturn strings.TrimRight(string(content), \"\\n\"), nil\n}\n\n// RuleDetail contains the resolved rule along with metadata about its source.","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L92-L128","documentation":"LoadDefault resolves each PathRules entry by reading rule_docs/<Rule> from the embedded FS. This error wraps that ReadFile failure and names both the missing rule file and the glob pattern that referenced it, so you know which map entry is broken.","triggerScenarios":"A path_rule_map value in system_rules.json points to a rule doc that does not exist under rule_docs/ — filename typo, deleted file, case mismatch, or reference to a file living outside rule_docs/.","commonSituations":"Adding a pattern like \"**/*.py\": \"python.md\" without creating rule_docs/python.md; renaming docs during cleanup; case-sensitive FS mismatch (Go.md vs go.md).","solutions":["Create the missing file at internal/config/rules/rule_docs/<name> or fix the path_rule_map value to reference an existing doc","List rule_docs/ (ls internal/config/rules/rule_docs/) and correct the exact, case-sensitive filename","If the rule text is obsolete, remove the pattern entry from path_rule_map instead"],"exampleFix":"// before\n{\"path_rule_map\": {\"**/*.py\": \"pyhton.md\"}}\n// after\n{\"path_rule_map\": {\"**/*.py\": \"python.md\"}}  // rule_docs/python.md exists","handlingStrategy":"validation","validationCode":"var probe struct {\n\tPathRuleMap map[string]string `json:\"path_rule_map\"`\n}\nif err := json.Unmarshal(systemRulesJSON, &probe); err != nil { return err }\nfor pattern, doc := range probe.PathRuleMap {\n\tif _, err := fs.Stat(docsFS, \"rule_docs/\"+doc); err != nil {\n\t\treturn fmt.Errorf(\"pattern %q references missing doc %q\", pattern, doc)\n\t}\n}","typeGuard":null,"tryCatchPattern":"rule, err := rules.LoadDefault()\nif err != nil {\n\tif strings.Contains(err.Error(), \"read rule file\") {\n\t\tvar missing string\n\t\tfmt.Sscanf(err.Error(), \"read rule file %q\", &missing)\n\t\tlog.Fatalf(\"path_rule_map references missing doc %q — create it under rule_docs/ or fix the reference\", missing)\n\t}\n\treturn err\n}","preventionTips":["When adding a pattern to path_rule_map, create the referenced doc in the same commit","CI check: extract all path_rule_map values and assert each exists in rule_docs/","Use consistent lowercase filenames to avoid case-sensitivity mismatches"],"tags":["embed","config","missing-file"],"backgroundTag":"embedded-asset-missing","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}