alibaba/open-code-review · error
walk %s: %w
Error message
walk %s: %w
What it means
In non-git directories, listFiles falls back to filepath.WalkDir (listFilesViaWalk). Any error returned by the walk (other than skipped entries) is wrapped as 'walk <repoDir>: ...'. Note per-entry errors are logged and skipped, so this surfaces only for fatal errors like context cancellation or the root being unreadable.
Source
Thrown at internal/scan/provider.go:240
if d.IsDir() {
// Skip the whole subtree if the dir itself is excluded.
if diff.IsPathExcluded(p.repoDir, rel, gitignorePatterns) {
return filepath.SkipDir
}
return nil
}
// Regular files only; skip symlinks / sockets / etc.
if !d.Type().IsRegular() {
return nil
}
if diff.IsPathExcluded(p.repoDir, rel, gitignorePatterns) {
return nil
}
files = append(files, rel)
return nil
})
if err != nil {
return nil, fmt.Errorf("walk %s: %w", p.repoDir, err)
}
return files, nil
}
func (p *Provider) gitLs(ctx context.Context, args ...string) ([]string, error) {
cmdArgs := append([]string{"-c", "core.quotepath=false", "ls-files"}, args...)
var out string
var err error
if p.runner != nil {
out, err = p.runner.Run(ctx, p.repoDir, cmdArgs...)
} else {
cmd := exec.CommandContext(ctx, "git", cmdArgs...)
cmd.Dir = p.repoDir
// Use Output (stdout only), not CombinedOutput: with -z, git emits
// NUL-delimited paths on stdout, and merging stderr in would corrupt
// the filename parsing below.
raw, runErr := cmd.Output()
out, err = string(raw), runErrView on GitHub (pinned to 5cf97d0d15)
Solutions
- Check the wrapped cause: if it is 'context deadline exceeded', raise the timeout or re-run.
- Ensure the scanned directory exists and is readable (ls the directory as the running user).
- Run `git init` if the directory should be a git repo, to use the more robust git path.
- Re-run pointing at the correct directory path.
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(repoDir)
if err != nil || !info.IsDir() {
return fmt.Errorf("cannot walk %s: not a readable directory", repoDir)
}
if _, err := os.ReadDir(repoDir); err != nil {
return fmt.Errorf("directory not readable: %w", err)
} Try / catch
files, err := provider.Enumerate(ctx)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("walk exceeded timeout: %w", err) // retry with bigger timeout
}
return err
} Prevention
- Verify the target directory exists and is readable before scanning.
- Initialize a git repo to use the more robust git-based enumeration.
- Provide sufficient timeout for large directory trees.
- Point the scan at the correct path; walk errors surface only for fatal issues.
When it happens
Trigger: Provider.listFiles → listFilesViaWalk when the directory is not a git repo, and filepath.WalkDir returns a non-nil error — almost always ctx.Err() (cancellation/deadline) propagated by the callback, or the root directory itself being inaccessible.
Common situations: Scanning a plain (non-git) folder whose root lacks read permission; scan timeout/cancel mid-walk; repoDir pointing at a nonexistent path.
Related errors
- read background file %q: %w
- background file %q is a directory, not a file
- load config: %w
- create config dir: %w
- write config: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/e831da6d05979183.
Report an issue: GitHub.