alibaba/open-code-review · error
resolve repository path %q: %w
Error message
resolve repository path %q: %w
What it means
readWorkspaceFileForDiff first canonicalizes the repository directory via pathutil.CanonicalPath; failure is wrapped as 'resolve repository path %q'. This usually means the repo directory does not exist, is inaccessible, or cannot be resolved to an absolute canonical path, so no workspace file diffing can proceed.
Source
Thrown at internal/diff/workspace_file.go:17
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 alibaba/open-code-review Contributors
package diff
import (
"fmt"
"os"
"path/filepath"
"github.com/alibaba/open-code-review/internal/pathutil"
)
func readWorkspaceFileForDiff(repoDir, relPath string) ([]byte, error) {
repoRoot, err := pathutil.CanonicalPath(repoDir)
if err != nil {
return nil, fmt.Errorf("resolve repository path %q: %w", repoDir, err)
}
if filepath.IsAbs(relPath) {
return nil, fmt.Errorf("file path %q must be relative, not absolute", relPath)
}
fullPath := filepath.Join(repoRoot, relPath)
if !pathutil.WithinBase(repoRoot, fullPath) {
return nil, fmt.Errorf("file path %q is outside repository", relPath)
}
parent, err := filepath.EvalSymlinks(filepath.Dir(fullPath))
if err != nil {
return nil, fmt.Errorf("resolve parent path for %q: %w", relPath, err)
}
if !pathutil.WithinBase(repoRoot, parent) {
return nil, fmt.Errorf("file path %q is outside repository", relPath)
}
View on GitHub (pinned to 5cf97d0d15)
Solutions
- Verify the repo directory exists and pass an absolute path (filepath.Abs or os.Getwd-based)
- Check read/execute permissions on the directory and its ancestors
- Remove or fix broken symlinks in the repo path
- Inspect the wrapped inner error (%w) for the exact filesystem failure
Example fix
// before
diffs, err := diff.GetDiff(ctx, params{dir: "../maybe-moved-repo"})
// after
abs, err := filepath.Abs("../repo")
if err != nil { return err }
if _, err := os.Stat(abs); err != nil { return err }
diffs, err := diff.GetDiff(ctx, params{dir: abs}) Defensive patterns
Strategy: validation
Validate before calling
abs, err := filepath.Abs(repoDir)
if err != nil { return err }
info, err := os.Stat(abs)
if err != nil || !info.IsDir() { return fmt.Errorf("repo dir %s unusable: %w", abs, err) } Try / catch
d, err := differ.GetDiff(ctx, p)
if err != nil && strings.HasPrefix(err.Error(), "resolve repository path") {
var pathErr *os.PathError
if errors.As(err, &pathErr) { return fmt.Errorf("repo path bad: %w", pathErr) }
return err
} Prevention
- Pass absolute, existing repo directories into the diff API
- Re-resolve repo paths after checkouts/moves instead of caching them
- Check symlink targets still exist in containerized/CI workspaces
When it happens
Trigger: Calling readWorkspaceFileForDiff (via untrackedFileDiffs/finalizeDiff during workspace diffing) with a repoDir that fails pathutil.CanonicalPath — nonexistent directory, permission issues on ancestors, or symlink/eval resolution errors.
Common situations: Running the diff against a stale/deleted checkout path; passing a relative repo dir from a different working directory; symlinked repo roots that no longer resolve; permission restrictions in containers/CI workspaces.
Related errors
- resolve repo dir %s: %w
- untracked file diff failed: %w
- resolve repository path %q: %w
- resolve file %q: %w
- read background file %q: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/75db406ef11f3930.
Report an issue: GitHub.