alibaba/open-code-review · error
enumerate files: %w
Error message
enumerate files: %w
What it means
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.
Source
Thrown at internal/scan/preview.go:32
// without dispatching any LLM calls. Returns a *model.Preview ready for
// cmd/opencodereview.outputPreviewText to render.
//
// It builds none of the scan runtime — no session or runner — so previewing
// cannot open session persistence. Going through NewAgent instead would
// auto-create a session and leave an unfinalized JSONL file under the OCR home.
func Preview(ctx context.Context, args Args) (*model.Preview, error) {
return (&Agent{args: args}).preview(ctx)
}
// preview is read-only with respect to the Agent: it does not mutate
// a.items. (Earlier versions did, which made a subsequent Run on the same
// Agent silently observe the preview's enumeration instead of re-running
// it.) Callers that want to reuse the enumeration should call Run once.
func (a *Agent) preview(ctx context.Context) (*model.Preview, error) {
provider := NewProvider(a.args.RepoDir, a.args.Paths, a.args.GitRunner, a.args.MaxFileSizeBytes)
items, err := provider.Enumerate(ctx)
if err != nil {
return nil, fmt.Errorf("enumerate files: %w", err)
}
// Pre-allocate Entries to a non-nil empty slice so JSON marshalling
// emits `"files":[]` rather than `"files":null` when there is nothing
// to review — important for downstream API consumers expecting an array.
result := &model.Preview{
TotalFiles: len(items),
Entries: make([]model.PreviewEntry, 0, len(items)),
}
for _, it := range items {
if err := ctx.Err(); err != nil {
return nil, err
}
entry := model.PreviewEntry{
Path: it.Path,
Status: "scan",
Insertions: int64(it.LineCount),View on GitHub (pinned to 5cf97d0d15)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(repoDir); err != nil {
return fmt.Errorf("repo dir unreadable before preview: %w", err)
}
cmd := exec.Command("git", "-C", repoDir, "rev-parse", "--git-dir")
_ = cmd.Run() // non-zero just means non-git; walk path will be used Type guard
func isEnumerateError(err error) bool {
return err != nil && strings.HasPrefix(err.Error(), "enumerate files:")
} Try / catch
preview, err := agent.preview(ctx)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
return fmt.Errorf("enumeration timed out; retry with a larger timeout")
}
return fmt.Errorf("preview failed: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: Running preview outside a writable/readable directory, corrupted git repo, context timeout/cancellation mid-enumeration, or the repo directory was deleted/moved after startup.
Related errors
- preview failed: %w
- preview failed: %w
- load diffs: %w
- git ls-files (tracked): %w
- git ls-files (untracked): %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/2cd1c28ce72eff8a.
Report an issue: GitHub.