{"record":{"id":"2cd1c28ce72eff8a","repo":"alibaba/open-code-review","slug":"enumerate-files-w-2cd1c2","errorCode":null,"errorMessage":"enumerate files: %w","messagePattern":"enumerate files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/scan/preview.go","lineNumber":32,"sourceCode":"// without dispatching any LLM calls. Returns a *model.Preview ready for\n// cmd/opencodereview.outputPreviewText to render.\n//\n// It builds none of the scan runtime — no session or runner — so previewing\n// cannot open session persistence. Going through NewAgent instead would\n// auto-create a session and leave an unfinalized JSONL file under the OCR home.\nfunc Preview(ctx context.Context, args Args) (*model.Preview, error) {\n\treturn (&Agent{args: args}).preview(ctx)\n}\n\n// preview is read-only with respect to the Agent: it does not mutate\n// a.items. (Earlier versions did, which made a subsequent Run on the same\n// Agent silently observe the preview's enumeration instead of re-running\n// it.) Callers that want to reuse the enumeration should call Run once.\nfunc (a *Agent) preview(ctx context.Context) (*model.Preview, error) {\n\tprovider := NewProvider(a.args.RepoDir, a.args.Paths, a.args.GitRunner, a.args.MaxFileSizeBytes)\n\titems, err := provider.Enumerate(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"enumerate files: %w\", err)\n\t}\n\n\t// Pre-allocate Entries to a non-nil empty slice so JSON marshalling\n\t// emits `\"files\":[]` rather than `\"files\":null` when there is nothing\n\t// to review — important for downstream API consumers expecting an array.\n\tresult := &model.Preview{\n\t\tTotalFiles: len(items),\n\t\tEntries:    make([]model.PreviewEntry, 0, len(items)),\n\t}\n\n\tfor _, it := range items {\n\t\tif err := ctx.Err(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tentry := model.PreviewEntry{\n\t\t\tPath:       it.Path,\n\t\t\tStatus:     \"scan\",\n\t\t\tInsertions: int64(it.LineCount),","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/scan/preview.go#L14-L50","documentation":"Agent.preview builds a model.Preview by first enumerating reviewable files via Provider.Enumerate. If that enumeration fails, the error is wrapped with 'enumerate files:' and preview aborts — no file list means no preview.","triggerScenarios":"Calling the preview flow (Agent.preview, reached via preview subcommands or Run) when Provider.Enumerate → listFiles fails: git ls-files errors in a git repo, or filepath.WalkDir errors in a non-git dir (e.g. context canceled, repo dir unreadable).","commonSituations":"Running preview outside a writable/readable directory, corrupted git repo, context timeout/cancellation mid-enumeration, or the repo directory was deleted/moved after startup.","solutions":["Run the command from inside a valid repository directory (git rev-parse succeeds).","Check underlying wrapped error: fix git ls-files failure or filesystem permission on the repo dir.","Increase the command timeout / avoid cancelling the context during enumeration.","If in a non-git dir, ensure the directory is readable and the root .gitignore is parseable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(repoDir); err != nil {\n    return fmt.Errorf(\"repo dir unreadable before preview: %w\", err)\n}\ncmd := exec.Command(\"git\", \"-C\", repoDir, \"rev-parse\", \"--git-dir\")\n_ = cmd.Run() // non-zero just means non-git; walk path will be used","typeGuard":"func isEnumerateError(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"enumerate files:\")\n}","tryCatchPattern":"preview, err := agent.preview(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {\n        return fmt.Errorf(\"enumeration timed out; retry with a larger timeout\")\n    }\n    return fmt.Errorf(\"preview failed: %w\", err)\n}","preventionTips":["Run the tool from a valid, readable repository directory.","Avoid cancelling the context during enumeration; set adequate timeouts.","Keep .git healthy — a corrupt repo makes git ls-files fail.","For non-git dirs, ensure the root is readable."],"tags":["file-enumeration","git","preview"],"backgroundTag":"file-enumeration-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}