Skip to content

fix(tool): keep the generic text in a search failure - #767

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/grep-empty-failure-message
Sep 28, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/grep-empty-failure-message

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

A search that fails on an unreadable path 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 precisely the case the fallback was written for. The tool passes
--no-messages, and the branch's own comment already says why:

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

So in the one branch that exists to explain an unreadable path, stderr is empty
by design and the model cannot tell a broken symlink or an unreadable subtree
from a real failure.

The fix builds the message in one place, with || for the empty-string case:

export function searchFailure(missing: string | undefined, detail: string) {
  return `Search failed: ${missing ?? (detail || "Some paths could not be searched.")}`
}

missing still wins, so a path that is not there names itself, and a real
ripgrep message still passes through — both unchanged.

Linked issue

Fixes #766

How did you verify it?

One test per branch of the message, added to backend/cli/test/tool/grep.test.ts:

  • names a missing path instead of the generic text
  • passes ripgrep's own stderr through when it said something
  • still says something when --no-messages left stderr empty — this is the one
    that fails on 3e94875c, where the same inputs produce Search failed: with
    an empty reason.

The two branches that already worked are pinned by the existing suite and still
pass, which is the point: a path that is not there says so, rather than blaming what could not be searched and invalid regex is a search failure, not an empty success both exercise the real tool.

Commands run:

  • bun test --timeout 30000 ./test/tool/grep.test.ts → 16 pass, 0 fail, 1 skip
    (the skip is the pre-existing does not follow a nested symlink outside the authorized search root, which needs a symlink this Windows checkout cannot
    create — EPERM)
  • bun run --cwd backend/cli typecheck → exit 0

Being straight about the evidence for the third test: I could not drive the
empty-stderr case through the real tool here, because the documented trigger is
a broken symlink and this checkout refuses to create symlinks (EPERM, no
Developer Mode). The defect itself is not in doubt — "" ?? "" ?? "x" evaluates
to "" — and the --no-messages flag plus the branch's own comment establish
that empty stderr is the expected input there. I extracted the message
construction so all three branches are testable on any platform, and asked in
the issue whether you would rather that case went through the tool instead.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts described in my other pull requests; backend typecheck is clean and the full grep suite is green
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not touched
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not touched
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — no doc change needed: this only makes an existing error message non-empty
  • Screenshots or a short video are attached for UI changes — not a UI change
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not touched

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

`??` only falls through on null and undefined, so the empty stderr that
`--no-messages` produces for exactly the failures this branch explains skipped
the fallback and left the message as "Search failed:" with no reason.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit a331b5f into synthetic-sciences:main Sep 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants