{"record":{"id":"90b0e3ec26797bfe","repo":"alibaba/open-code-review","slug":"untracked-file-diff-failed-w","errorCode":null,"errorMessage":"untracked file diff failed: %w","messagePattern":"untracked file diff failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/diff/git.go","lineNumber":215,"sourceCode":"\t\t}\n\t\tcombined.WriteString(out)\n\n\tcase ModeWorkspace:\n\t\t// The stderr returned here is the fallback's (`git diff --staged`), and\n\t\t// that is the one worth surfacing. Reaching the fallback at all means\n\t\t// `git diff HEAD` already failed, and in the case the fallback exists\n\t\t// for — a repository with no commits — it failed with \"bad revision\n\t\t// 'HEAD'\", which is expected rather than diagnostic. Only the second\n\t\t// failure describes what actually blocked the review.\n\t\ttracked, stderr, err := p.workspaceTrackedDiff(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, gitFailure(\"workspace tracked diff\", stderr, err)\n\t\t}\n\t\tcombined.WriteString(tracked)\n\n\t\tuntracked, err := p.untrackedFileDiffs(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"untracked file diff failed: %w\", err)\n\t\t}\n\t\tfor _, ud := range untracked {\n\t\t\tcombined.WriteString(ud)\n\t\t\tcombined.WriteString(\"\\n\\n\")\n\t\t}\n\t}\n\n\tvar ref string\n\tswitch p.mode {\n\tcase ModeRange:\n\t\tref = p.to\n\tcase ModeCommit:\n\t\tref = p.commit\n\t}\n\n\tdiffs, err := ParseDiffText(ctx, combined.String(), p.repoDir, ref, p.runner)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/diff/git.go#L197-L233","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped inner error (%w) to see which file/read failed","Fix permissions or remove problematic untracked files (broken symlinks, sockets)","Ensure the repo directory is accessible and resolvable (see error 239's cause)","Stage or .gitignore files you do not want included in the workspace diff"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"d, err := differ.GetDiff(ctx, p)\nif err != nil {\n    var ufErr interface{ Unwrap() error }\n    if errors.Is(err, os.ErrPermission) { /* skip unreadable untracked files and retry */ }\n    return fmt.Errorf(\"workspace diff: %w\", err)\n}","preventionTips":["Keep the working tree free of unreadable/broken untracked entries","Gitignore generated artifacts that should not be diffed","Ensure the repo root is accessible before running workspace diffs"],"tags":["git","diff","untracked-files","workspace"],"backgroundTag":"untracked-file-diff-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}