alibaba/open-code-review · error
resolve repository path %q: %w
Error message
resolve repository path %q: %w
What it means
Error from FileReader.resolveWorkspacePath when pathutil.CanonicalPath fails on fr.RepoDir — the repository root itself cannot be canonicalized (e.g. it does not exist or a path component is not resolvable). No file-specific validation happens; this is a configuration-level failure of the FileReader's RepoDir setting.
Source
Thrown at internal/tool/filereader.go:97
}
}
func (fr *FileReader) readFromDisk(path string) (string, error) {
fullPath, err := fr.resolveWorkspacePath(path)
if err != nil {
return "", err
}
content, err := os.ReadFile(fullPath)
if err != nil {
return "", fmt.Errorf("read file %q: %w", path, err)
}
return string(content), nil
}
func (fr *FileReader) resolveWorkspacePath(path string) (string, error) {
repoRoot, err := pathutil.CanonicalPath(fr.RepoDir)
if err != nil {
return "", fmt.Errorf("resolve repository path %q: %w", fr.RepoDir, err)
}
fullPath := filepath.Join(repoRoot, path)
if !pathutil.WithinBase(repoRoot, fullPath) {
return "", fmt.Errorf("file path %q is outside repository", path)
}
resolvedPath, err := filepath.EvalSymlinks(fullPath)
if err != nil {
if os.IsNotExist(err) {
return fullPath, nil
}
return "", fmt.Errorf("resolve file %q: %w", path, err)
}
if !pathutil.WithinBase(repoRoot, resolvedPath) {
return "", fmt.Errorf("file path %q is outside repository", path)
}
return resolvedPath, nilView on GitHub (pinned to 5cf97d0d15)
Solutions
- Verify RepoDir points to an existing directory (ls <RepoDir>) and correct the value.
- Run the tool from inside the repository if RepoDir is derived from the working directory.
- Recreate the missing directory or fix the broken symlink that RepoDir points through.
Example fix
// before
fr := &tool.FileReader{RepoDir: "/tmp/stale-worktree"}
// after
fr := &tool.FileReader{RepoDir: "/home/dev/project"} // existing repo root Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(repoDir)
if err != nil { return fmt.Errorf("repo dir %q: %w", repoDir, err) }
if !info.IsDir() { return fmt.Errorf("%q is not a directory", repoDir) }
if _, err := filepath.EvalSymlinks(repoDir); err != nil { return fmt.Errorf("cannot resolve %q: %w", repoDir, err) } Type guard
func validRepoDir(dir string) bool { info, err := os.Stat(dir); return err == nil && info.IsDir() } Try / catch
content, err := fr.Read(ctx, rel)
if err != nil && strings.Contains(err.Error(), "resolve repository path") {
return nil, fmt.Errorf("FileReader misconfigured: set RepoDir to an existing directory: %w", err)
} Prevention
- Set RepoDir from an absolute, verified path (filepath.Abs + os.Stat) at startup.
- Prefer resolving RepoDir via git rev-parse --show-toplevel rather than cwd assumptions.
- Fail fast with a clear message if RepoDir does not exist, instead of letting reads fail later.
When it happens
Trigger: Constructing FileReader with a RepoDir that is a non-existent path, a broken symlink, or otherwise uncanonicalizable, then calling Read/ReadLines in workspace mode so readFromDisk/readLinesFromDisk invoke resolveWorkspacePath.
Common situations: Running the CLI outside a git repository or with a bad --repo flag; RepoDir pointing to a deleted temp directory; renamed/moved project root; wrong working directory when RepoDir defaults to cwd.
Related errors
- resolve repository path %q: %w
- read file %q: %w
- read app config %s: %w
- load rules: %w
- resolve LLM endpoint: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/fc18091b976716ee.
Report an issue: GitHub.