{"record":{"id":"9bf0fdd0e0b01579","repo":"alibaba/open-code-review","slug":"scan-preview-failed-w","errorCode":null,"errorMessage":"scan preview failed: %w","messagePattern":"scan preview failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/scan_cmd.go","lineNumber":278,"sourceCode":"\tif state.CompletedCount() == 0 {\n\t\treturn nil, fmt.Errorf(\"resume session %q has no completed scan items (run 'ocr session list' to see available sessions)\", opts.resume)\n\t}\n\treturn state, nil\n}\n\nfunc runScanPreview(cc *commonContext, scanTpl *template.ScanTemplate, scanPaths []string, outputFormat string, out io.Writer) error {\n\tpreview, err := scan.Preview(context.Background(), scan.Args{\n\t\tRepoDir:          cc.RepoDir,\n\t\tPaths:            scanPaths,\n\t\tFileFilter:       cc.FileFilter,\n\t\tGitRunner:        cc.GitRunner,\n\t\tMaxFileSizeBytes: scanTpl.MaxFileSizeBytes,\n\t\t// Template's prompt fields are unused by Preview; pass the same\n\t\t// value so MaxFileSizeBytes is consistent.\n\t\tTemplate: *scanTpl,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"scan preview failed: %w\", err)\n\t}\n\treturn outputPreview(preview, outputFormat, out)\n}\n","sourceCodeStart":260,"sourceCodeEnd":282,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/scan_cmd.go#L260-L282","documentation":"With `ocr scan --preview`, the CLI enumerates which files would be scanned (respecting template budgets like MaxFileSizeBytes) via scan.Preview, without calling the LLM. Any error from that enumeration (path resolution, git/traversal failure, IO) is wrapped as \"scan preview failed: %w\".","triggerScenarios":"Running `ocr scan --preview` when scan.Args enumeration fails: invalid --path entries, a broken git worktree, unreadable directories, or errors applying the template's file-size constraints.","commonSituations":"Passing a --path that doesn't exist or is outside the repo; running outside a git repository; permission errors on subdirectories; glob typos in --exclude.","solutions":["Check each --path exists inside the repository and is spelled correctly.","Run from the repository root (or pass the right repo dir) so file traversal works.","Simplify --exclude globs to rule out a bad pattern, then add them back one at a time.","Read the wrapped cause — it names the failing path or git operation."],"exampleFix":"// before\nocr scan --preview --path interal/agent\n// after\nocr scan --preview --path internal/agent","handlingStrategy":"validation","validationCode":"for _, p := range splitPaths(opts.paths) {\n    if _, err := os.Stat(filepath.Join(repoDir, p)); err != nil {\n        return fmt.Errorf(\"--path %q does not exist in repo\", p)\n    }\n}\nif _, err := exec.Command(\"git\", \"-C\", repoDir, \"rev-parse\", \"--git-dir\").Output(); err != nil {\n    return fmt.Errorf(\"not a git repository: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runScanPreview(cc, scanTpl, scanPaths, format, out); err != nil {\n    log.Fatalf(\"scan preview failed: %v\", err) // inner error names the bad path/glob\n}","preventionTips":["Always run preview from the repository root.","Verify --path arguments exist before invoking.","Test --exclude globs incrementally; a bad pattern can break enumeration.","Ensure read permissions on all directories you intend to scan."],"tags":["go","cli","scan","preview"],"backgroundTag":"file-enumeration-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}