alibaba/open-code-review · error

stat file %q: %w

Error message

stat file %q: %w

What it means

os.Lstat on the joined path failed — the file reported as changed (e.g. untracked) no longer exists or cannot be stat'ed. Common when the working tree is modified between git listing the file and reading it, or on permission problems.

Source

Thrown at internal/diff/workspace_file.go:38

		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)
	}

	info, err := os.Lstat(fullPath)
	if err != nil {
		return nil, fmt.Errorf("stat file %q: %w", relPath, err)
	}
	if info.IsDir() {
		return nil, fmt.Errorf("file path %q is a directory", relPath)
	}
	if info.Mode()&os.ModeSymlink != 0 {
		target, err := os.Readlink(fullPath)
		if err != nil {
			return nil, fmt.Errorf("read symlink %q: %w", relPath, err)
		}
		return []byte(target), nil
	}

	resolvedPath, err := filepath.EvalSymlinks(fullPath)
	if err != nil {
		return nil, fmt.Errorf("resolve file %q: %w", relPath, err)
	}
	if !pathutil.WithinBase(repoRoot, resolvedPath) {
		return nil, fmt.Errorf("file path %q is outside repository", relPath)

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Check the wrapped error: ENOENT means the file was deleted between diff collection and read; EACCES means permission is missing
  2. Refresh the file list (re-run git status) if the working tree changed concurrently
  3. Ensure the process has read permission for the file
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/diff/workspace_file.go:38 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/cf920fe60ea259b9. Report an issue: GitHub.