{"record":{"id":"a8fee5f82d96ab1f","repo":"alibaba/open-code-review","slug":"load-rules-w-a8fee5","errorCode":null,"errorMessage":"load rules: %w","messagePattern":"load rules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared.go","lineNumber":117,"sourceCode":"\tif err := tpl.Validate(); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid config: %w\", err)\n\t}\n\n\trepoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Built before the resolver: the sniffer reads file content at contentRef\n\t// through this limiter.\n\tgitRunner := gitcmd.New(maxGitProcs)\n\n\tresolver, fileFilter, err := rules.NewResolver(repoDir, rulePath, rules.ResolverOptions{\n\t\tRef:    contentRef,\n\t\tRunner: gitRunner,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load rules: %w\", err)\n\t}\n\n\treturn &commonContext{\n\t\tTemplate:   tpl,\n\t\tRepoDir:    repoDir,\n\t\tResolver:   resolver,\n\t\tFileFilter: fileFilter,\n\t\tGitRunner:  gitRunner,\n\t\tIsGitRepo:  isGit,\n\t}, nil\n}\n\n// resolveWorkingDir returns (absPath, isGitRepo, err). When requireGit is\n// true, returns an error if the directory is not a git repo. When false,\n// returns IsGitRepo=false instead of erroring (scan path uses this).\nfunc resolveWorkingDir(input string, requireGit bool) (string, bool, error) {\n\tif input == \"\" {\n\t\twd, err := os.Getwd()","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared.go#L99-L135","documentation":"loadCommonContext wraps a failure from rules.NewResolver, which builds the rule resolver/file filter for the run (optionally reading rules from a git ref via gitRunner). Causes include: the rules file/pattern doesn't exist or is unreadable, rule syntax is invalid, or the git ref operation failed when Ref is set.","triggerScenarios":"Passing --rules pointing at a missing/malformed file; running with contentRef set where the git ref/commit doesn't exist or git isn't available in the repo; a rules directory with an invalid rule definition.","commonSituations":"Typo in the rules path; rules file edited and broken; scanning an older commit whose rules file differs; running outside a git repo while rules resolution requires git.","solutions":["Check the rules path exists and parses; fix or remove invalid rule definitions","If resolving rules at a ref, confirm the ref/commit exists (`git rev-parse <ref>`) and you are inside the repo","Run without a custom --rules flag to isolate whether default rules or your file is the problem"],"exampleFix":"// before\nocr review --rules ./missing-rules.yaml\n// after\nocr review --rules ./config/review-rules.yaml   # existing, valid file","handlingStrategy":"validation","validationCode":"// check rules target before running\nif _, err := os.Stat(rulePath); err != nil {\n    return fmt.Errorf(\"rules file missing: %w\", err)\n}\nif contentRef != \"\" {\n    if err := exec.Command(\"git\", \"rev-parse\", \"--verify\", contentRef).Run(); err != nil {\n        return fmt.Errorf(\"ref %q not found\", contentRef)\n    }\n}","typeGuard":null,"tryCatchPattern":"resolver, _, err := rules.NewResolver(repoDir, rulePath, opts)\nif err != nil {\n    return nil, fmt.Errorf(\"load rules: %w\", err)\n}","preventionTips":["Validate the --rules path and YAML syntax before submitting review runs","Confirm git refs exist when resolving rules at a commit","Run ocr from inside the repository so git-based rule resolution works"],"tags":["go","rules","config","file-not-found"],"backgroundTag":"rule-load-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}