alibaba/open-code-review · error
resolve path: %w
Error message
resolve path: %w
What it means
requireGitRepo converts the supplied directory to an absolute path before probing it with `git rev-parse --git-dir`. If filepath.Abs fails, the error is wrapped as "resolve path". filepath.Abs only fails when the working directory or the path cannot be resolved (e.g. deleted cwd), so this is rare.
Source
Thrown at cmd/opencodereview/review_cmd.go:450
return session.ReviewModeRange
}
return session.ReviewModeWorkspace
}
// resolveRepoDir resolves the repo dir for `ocr rules check`. It delegates to
// resolveWorkingDir(requireGit=true) so it anchors at the git top-level just
// like the review path — keeping rule resolution consistent when run from a
// monorepo subdirectory (#287).
func resolveRepoDir(input string) (string, error) {
absPath, _, err := resolveWorkingDir(input, true)
return absPath, err
}
// requireGitRepo validates that the given directory is part of a git repository.
func requireGitRepo(dir string) error {
repoDir, err := filepath.Abs(dir)
if err != nil {
return fmt.Errorf("resolve path: %w", err)
}
out, err := runGitCmd(repoDir, "rev-parse", "--git-dir")
if err != nil || len(out) == 0 {
return fmt.Errorf("%s is not a git repository, code review requires a valid git repository", repoDir)
}
return nil
}
// validateReviewRefs rejects ref-option injection (#112): any --from/--to/
// --commit value must be a real commit ref and must not start with '-'.
func validateReviewRefs(repoDir string, opts reviewOptions) error {
refs := []struct {
flag string
ref string
}{
{"--from", opts.from},
{"--to", opts.to},
{"--commit", opts.commit},View on GitHub (pinned to 5cf97d0d15)
Solutions
- Re-run the command from an existing directory (`cd` to a valid path first).
- Verify the directory passed to requireGitRepo exists and its ancestors are accessible (ls the parent chain).
- Check for permission issues on ancestor directories (`namei -l /path/to/dir`).
Example fix
// before (cwd deleted) ocr rules check --repo . file.go // after cd /valid/path && ocr rules check --repo . file.go
Defensive patterns
Strategy: validation
Validate before calling
abs, err := filepath.Abs(dir)
if err != nil {
return fmt.Errorf("resolve path: %w", err)
}
if _, err := os.Stat(abs); err != nil {
return fmt.Errorf("directory %s unavailable: %w", abs, err)
} Try / catch
if err := requireGitRepo(dir); err != nil {
if strings.Contains(err.Error(), "resolve path") {
// cwd or path invalid; chdir to a valid directory first
}
return err
} Prevention
- Never delete/rename the directory the process is running from.
- Use absolute --repo paths in scripts and CI.
- Check ancestor-directory permissions when paths behave oddly.
When it happens
Trigger: Calling requireGitRepo (directly or via tests TestRequireGitRepo_Valid/Invalid) with a path that cannot be made absolute — typically because the current working directory no longer exists.
Common situations: Running the CLI from a directory that was deleted or renamed while the process held it as cwd; symlink/permission problems on an ancestor directory.
Related errors
- read background file %q: %w
- background file %q is a directory, not a file
- load config: %w
- create config dir: %w
- write config: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/03373a3cca8bd293.
Report an issue: GitHub.