{"record":{"id":"5e24514e5c4f9bbe","repo":"alibaba/open-code-review","slug":"load-diffs-w-5e2451","errorCode":null,"errorMessage":"load diffs: %w","messagePattern":"load diffs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/preview.go","lineNumber":74,"sourceCode":"\t\treturn ExcludeDefaultPath\n\t}\n\n\treturn ExcludeNone\n}\n\n// Preview loads diffs and applies the filter algorithm, returning structured\n// preview data without dispatching any LLM calls.\n//\n// It builds none of the review runtime — no session, manifest, or runner — so\n// previewing cannot open session persistence. Going through New instead would\n// auto-create a session and leave an unfinalized JSONL file under the OCR home.\nfunc Preview(ctx context.Context, args Args) (*DiffPreview, error) {\n\treturn (&Agent{args: args}).preview(ctx)\n}\n\nfunc (a *Agent) preview(ctx context.Context) (*DiffPreview, error) {\n\tif err := a.loadDiffs(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"load diffs: %w\", err)\n\t}\n\n\tresult := &DiffPreview{\n\t\tTotalInsertions: a.totalInsertions,\n\t\tTotalDeletions:  a.totalDeletions,\n\t\tTotalFiles:      len(a.diffs),\n\t\t// Non-nil so an empty diff marshals as `\"files\":[]`, not `\"files\":null`.\n\t\tEntries: make([]DiffPreviewEntry, 0, len(a.diffs)),\n\t}\n\n\tfor _, d := range a.diffs {\n\t\tpath := effectivePath(d)\n\t\tentry := DiffPreviewEntry{\n\t\t\tPath:       path,\n\t\t\tInsertions: d.Insertions,\n\t\t\tDeletions:  d.Deletions,\n\t\t\tStatus:     diffStatus(d),\n\t\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/agent/preview.go#L56-L92","documentation":"The agent Preview method wraps any loadDiffs failure with the 'load diffs:' prefix when producing a DiffPreview (insertions/deletions/file counts) without running a review. Since preview only reads git state, this error means the git diff could not be loaded for the given Args — the wrapped error carries the actual git cause. It is identical in origin to the ResolveIdentity 'load diffs' error but on the preview entry point.","triggerScenarios":"agent.Preview (or Agent.preview) called with a RepoDir that is not a git repo, refs that do not resolve, or when the underlying git diff command fails (corrupt index, missing objects, runner error).","commonSituations":"Running preview from the wrong working directory; typo'd --from/--to; shallow CI clones lacking the target commit; detached repos after history rewrites.","solutions":["Validate RepoDir is a git work tree and the From/To/Commit refs resolve ('git rev-parse --verify') before calling Preview","Read the wrapped error for the exact git failure","Fetch/unshallow if commits are missing in CI","Fix the ref arguments and retry"],"exampleFix":"// before\nprev, err := agent.Preview(ctx, args) // 'load diffs: ... unknown revision'\n// after\nif err := checkRef(args.RepoDir, args.From); err != nil { return err }\nif err := checkRef(args.RepoDir, args.To); err != nil { return err }\nprev, err := agent.Preview(ctx, args)","handlingStrategy":"validation","validationCode":"func previewSafe(repoDir, from, to string) error {\n    if out, err := execGit(repoDir, \"rev-parse\", \"--is-inside-work-tree\"); err != nil || strings.TrimSpace(out) != \"true\" {\n        return fmt.Errorf(\"%s is not a git work tree\", repoDir)\n    }\n    for _, r := range []string{from, to} {\n        if r != \"\" && execGit(repoDir, \"rev-parse\", \"--verify\", r+\"^{commit}\") != nil {\n            return fmt.Errorf(\"ref %q missing\", r)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"prev, err := agent.Preview(ctx, args)\nif err != nil {\n    if strings.Contains(err.Error(), \"load diffs:\") {\n        log.Warnf(\"preview unavailable for %v: %v\", args, err)\n        return emptyPreview(), nil\n    }\n    return err\n}","preventionTips":["Check RepoDir and ref validity before preview","Fetch missing commits in CI before running preview","Degrade gracefully: show an empty/zero preview instead of failing the CLI","Keep From/To sources (flags, env, CI vars) validated at input boundary"],"tags":["git","diff-loading","preview"],"backgroundTag":"git-ref-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}