Hmbown/CodeWhale · error · anyhow::Error

search root does not exist

Error message

search root does not exist: {}

What it means

search_files walks the eval workspace root with the ignore crate's WalkBuilder to run regex searches. Before walking it checks that the root path exists; if not, it fails with the path's display form. This guards against searching a deleted or never-created workspace directory.

Solutions

  1. Check the printed root path exists; create the workspace or correct the configured root.
  2. Ensure earlier eval steps (workspace setup) ran before the search step.
  3. Use an absolute path for the workspace root to avoid cwd-dependent resolution.
Defensive patterns

Strategy: validation

Validate before calling

if !root.exists() {
    eprintln!("workspace root {} missing; run setup first", root.display());
    return;
}

Try / catch

match search_files(&root, pattern) {
    Err(e) if e.to_string().starts_with("search root does not exist") => {
        recreate_workspace(&root)?;
        search_files(&root, pattern)?
    }
    other => other?,
}

Prevention

When it happens

Trigger: run() invokes search_files with a root Path that does not exist on disk (workspace never initialized, deleted between steps, or wrong path constructed).

Common situations: Eval workspace cleanup removed the directory before a later search step; misconfigured workspace root path; relative path resolved against an unexpected cwd.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/ca626891a58090f1. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/eval.rs:622

fn read_workspace_file(path: &Path) -> Result<String> {
    fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct SearchMatch {
    path: PathBuf,
    line: usize,
    content: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct SearchResult {
    matches: Vec<SearchMatch>,
}

fn search_files(root: &Path, pattern: &str) -> Result<SearchResult> {
    if !root.exists() {
        return Err(anyhow!("search root does not exist: {}", root.display()));
    }

    let regex = Regex::new(pattern).context("failed to compile search regex")?;
    let mut matches = Vec::new();

    let walker = WalkBuilder::new(root)
        .hidden(false)
        .git_ignore(false)
        .git_global(false)
        .git_exclude(false)
        .build();

    for entry in walker {
        let entry = entry.with_context(|| format!("failed to walk {}", root.display()))?;
        if !entry.file_type().is_some_and(|t| t.is_file()) {
            continue;
        }

View on GitHub (pinned to 73e0f67d83)