Skip to content

A search failure can report Search failed with no reason at all #766

Closed

Description

What happened?

When a search fails because a path could not be read, the tool reports nothing
usable:

Search failed:

The message is built with a nullish coalescing chain:

const detail = errorOutput.trim()
const missing = await fs
  .stat(searchPath)
  .then(() => undefined)
  .catch(() => `No such file or directory: ${searchPath}`)
throw new Error(`Search failed: ${missing ?? detail ?? "Some paths could not be searched."}`)

?? only falls through on null and undefined. detail is "" whenever
stderr is empty, and "" ?? x is "", not x — so the generic text at the end
of the chain is unreachable and the message ends up empty.

This is exactly the case the fallback was written for. The tool passes
--no-messages, which suppresses ripgrep's per-file errors, and the code's own
comment says so:

// With --no-messages, we suppress error output but still get exit code 2 for
// broken symlinks etc.

So in the branch that exists to explain an unreadable path, stderr is empty by
design, and the model gets Search failed: with nothing after it. It cannot
tell a broken symlink or an unreadable subtree from a real failure.

The two branches that do work are fine: a missing path names itself, and an
invalid pattern passes ripgrep's own message through.

Steps to reproduce

  1. Search a directory that exists but cannot be read — a broken symlink is the
    documented trigger, since --no-messages silences the message ripgrep would
    otherwise print for it.
  2. Read the thrown error: it is Search failed: with an empty reason.

The three focused regressions in test/tool/grep.test.ts cover each branch of
the message. The empty-stderr branch is pinned by a unit test because
reproducing it end to end needs a broken symlink, which is POSIX-only; please
tell me if you would rather that case were driven through the tool.

How did you install OpenScience?

From source (bun dev).

OpenScience version

Source commit 3e94875c.

Provider and model

Not applicable; the defect is in the error the tool raises, before any model call.

Operating system

Not OS-specific. The silent case is easiest to reach on POSIX (a broken symlink);
on Windows an unreadable directory produces the same empty stderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions