alibaba/open-code-review · error
load rules: %w
Error message
load rules: %w
What it means
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.
Source
Thrown at cmd/opencodereview/shared.go:117
if err := tpl.Validate(); err != nil {
return nil, fmt.Errorf("invalid config: %w", err)
}
repoDir, isGit, err := resolveWorkingDir(repoDirInput, requireGit)
if err != nil {
return nil, err
}
// Built before the resolver: the sniffer reads file content at contentRef
// through this limiter.
gitRunner := gitcmd.New(maxGitProcs)
resolver, fileFilter, err := rules.NewResolver(repoDir, rulePath, rules.ResolverOptions{
Ref: contentRef,
Runner: gitRunner,
})
if err != nil {
return nil, fmt.Errorf("load rules: %w", err)
}
return &commonContext{
Template: tpl,
RepoDir: repoDir,
Resolver: resolver,
FileFilter: fileFilter,
GitRunner: gitRunner,
IsGitRepo: isGit,
}, nil
}
// resolveWorkingDir returns (absPath, isGitRepo, err). When requireGit is
// true, returns an error if the directory is not a git repo. When false,
// returns IsGitRepo=false instead of erroring (scan path uses this).
func resolveWorkingDir(input string, requireGit bool) (string, bool, error) {
if input == "" {
wd, err := os.Getwd()View on GitHub (pinned to 5cf97d0d15)
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
Example fix
// before ocr review --rules ./missing-rules.yaml // after ocr review --rules ./config/review-rules.yaml # existing, valid file
Defensive patterns
Strategy: validation
Validate before calling
// check rules target before running
if _, err := os.Stat(rulePath); err != nil {
return fmt.Errorf("rules file missing: %w", err)
}
if contentRef != "" {
if err := exec.Command("git", "rev-parse", "--verify", contentRef).Run(); err != nil {
return fmt.Errorf("ref %q not found", contentRef)
}
} Try / catch
resolver, _, err := rules.NewResolver(repoDir, rulePath, opts)
if err != nil {
return nil, fmt.Errorf("load rules: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- MCP server %q not found
- custom provider %q not found
- parse config: %w
- read app config %s: %w
- parse app config: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/a8fee5f82d96ab1f.
Report an issue: GitHub.