alibaba/open-code-review · error

untracked file diff failed: %w

Error message

untracked file diff failed: %w

What it means

In workspace mode, GetDiff diffs tracked changes, then calls untrackedFileDiffs to produce diffs for untracked files; if that helper returns an error, it is wrapped as 'untracked file diff failed'. The cause is inside untrackedFileDiffs (e.g. reading or diffing an untracked file failed), not in git itself reporting a top-level failure.

Source

Thrown at internal/diff/git.go:215

		}
		combined.WriteString(out)

	case ModeWorkspace:
		// The stderr returned here is the fallback's (`git diff --staged`), and
		// that is the one worth surfacing. Reaching the fallback at all means
		// `git diff HEAD` already failed, and in the case the fallback exists
		// for — a repository with no commits — it failed with "bad revision
		// 'HEAD'", which is expected rather than diagnostic. Only the second
		// failure describes what actually blocked the review.
		tracked, stderr, err := p.workspaceTrackedDiff(ctx)
		if err != nil {
			return nil, gitFailure("workspace tracked diff", stderr, err)
		}
		combined.WriteString(tracked)

		untracked, err := p.untrackedFileDiffs(ctx)
		if err != nil {
			return nil, fmt.Errorf("untracked file diff failed: %w", err)
		}
		for _, ud := range untracked {
			combined.WriteString(ud)
			combined.WriteString("\n\n")
		}
	}

	var ref string
	switch p.mode {
	case ModeRange:
		ref = p.to
	case ModeCommit:
		ref = p.commit
	}

	diffs, err := ParseDiffText(ctx, combined.String(), p.repoDir, ref, p.runner)
	if err != nil {
		return nil, err

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Inspect the wrapped inner error (%w) to see which file/read failed
  2. Fix permissions or remove problematic untracked files (broken symlinks, sockets)
  3. Ensure the repo directory is accessible and resolvable (see error 239's cause)
  4. Stage or .gitignore files you do not want included in the workspace diff
Defensive patterns

Strategy: try-catch

Try / catch

d, err := differ.GetDiff(ctx, p)
if err != nil {
    var ufErr interface{ Unwrap() error }
    if errors.Is(err, os.ErrPermission) { /* skip unreadable untracked files and retry */ }
    return fmt.Errorf("workspace diff: %w", err)
}

Prevention

When it happens

Trigger: GetDiff in workspace mode where untrackedFileDiffs fails — typically readWorkspaceFileForDiff rejecting or failing on a candidate untracked path (unreadable file, path resolution error), or an internal git diff invocation for a synthesized path failing.

Common situations: Untracked files with unreadable permissions; broken symlinks or special files in the working tree; path resolution of the repo root failing; non-ASCII or odd paths tripping filtering logic.

Related errors


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