{"record":{"id":"f4ff445d4a1dde36","repo":"alibaba/open-code-review","slug":"load-rules-w","errorCode":null,"errorMessage":"load rules: %w","messagePattern":"load rules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/rules_cmd.go","lineNumber":53,"sourceCode":"\t\treturn runRulesCheck(args[0])\n\t},\n}\n\nfunc init() {\n\taddRepoFlag(rulesCheckCmd, &rulesCheckRepoDir)\n\trulesCheckCmd.Flags().StringVar(&rulesCheckRulePath, \"rule\", \"\", \"path to a custom rule JSON file\")\n\trulesCmd.AddCommand(rulesCheckCmd)\n}\n\nfunc runRulesCheck(filePath string) error {\n\tresolvedRepo, err := resolveRepoDir(rulesCheckRepoDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tresolver, _, err := rules.NewResolver(resolvedRepo, rulesCheckRulePath, rules.ResolverOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"load rules: %w\", err)\n\t}\n\n\tdr, ok := resolver.(rules.DetailResolver)\n\tif !ok {\n\t\treturn fmt.Errorf(\"resolver does not support detail inspection\")\n\t}\n\n\tdetail := dr.ResolveDetail(filePath)\n\n\tsourceLabel := map[string]string{\n\t\t\"custom\":  \"Custom (--rule)\",\n\t\t\"project\": \"Project (.opencodereview/rule.json)\",\n\t\t\"global\":  \"Global (~/.opencodereview/rule.json)\",\n\t\t\"system\":  \"System built-in\",\n\t}\n\n\tfmt.Printf(\"File: %s\\n\", filePath)\n\tfmt.Printf(\"Source: %s\\n\", sourceLabel[detail.Source])","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/rules_cmd.go#L35-L71","documentation":"runRulesCheck builds a rules.Resolver from the repo and any --rule file. If NewResolver fails — malformed custom rule JSON, unreadable project/global rule file, or IO errors — it is wrapped as \"load rules\". No rule detail can be shown until the rule set loads.","triggerScenarios":"`ocr rules check <file>` (or --repo variant) with a broken --rule JSON, a corrupt ~/.opencodereview/rule.json or .opencodereview/rule.json, or permission errors reading those files.","commonSituations":"Hand-edited custom rule file with invalid JSON; rule file referencing missing paths; upgrading the tool to a schema the old rule file no longer satisfies.","solutions":["Look at the wrapped cause for the specific file/parse error.","Validate your rule JSON (e.g. `jq . rule.json`) and fix syntax/schema issues.","Temporarily move ~/.opencodereview/rule.json aside to see if the global layer is the culprit.","Check file permissions on the rule file and repo path."],"exampleFix":"// before\nocr rules check --rule custom.json src/a.xml   # custom.json has a trailing comma\n// after\njq . custom.json   # fix the JSON error it reports\nocr rules check --rule custom.json src/a.xml","handlingStrategy":"validation","validationCode":"for _, f := range []string{rulePath, \".opencodereview/rule.json\", os.Getenv(\"HOME\") + \"/.opencodereview/rule.json\"} {\n    if f == \"\" { continue }\n    if data, err := os.ReadFile(f); err == nil && !json.Valid(data) {\n        return fmt.Errorf(\"invalid rule JSON: %s\", f)\n    }\n}","typeGuard":null,"tryCatchPattern":"resolver, _, err := rules.NewResolver(repo, rulePath, rules.ResolverOptions{})\nif err != nil {\n    return fmt.Errorf(\"load rules: %w\", err) // surface wrapped cause to user\n}","preventionTips":["Validate rule JSON with `jq .` or a schema check after every edit.","Keep custom rule files under version control so bad edits are revertible.","Check permissions on global/project rule files before running in CI."],"tags":["rules","configuration","json"],"backgroundTag":"rule-load-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}