-
Notifications
You must be signed in to change notification settings - Fork 5
Detect malformed WarpGrep Windows results and surface actionable error #7
Description
Summary
- detect obviously malformed Windows search results, such as drive-letter-only file paths like
C - surface a clear actionable plugin error instead of confusing output like
Search failed: undefined - add regression tests covering malformed result handling
Problem
On Windows, the code search tool can produce malformed contexts like:
{
success: true,
contexts: [
{ file: 'C', content: '', lines: '*' }
]
}
Or user-facing failures like:
Search failed: undefined
From local reproduction, the root cause appears to be upstream in the SDK, where finish-file parsing truncates Windows paths at the drive-letter colon.
For example:
C:/Users/Test/Documents/project/src/auth.ts:1-50
is effectively reduced to:
{ path: 'C', lines: '*' }
This plugin cannot reconstruct the original path once it has been truncated, but it can detect the malformed result and fail clearly.
Why this PR belongs here
The parsing bug appears to live upstream in the SDK, but this plugin is the user-facing integration layer. Today, the plugin exposes misleading output that makes the failure hard to understand and hard to report.
This PR improves the UX by:
- detecting broken search payloads
- returning an explicit Windows-path-parsing error
- pointing users toward temporary workarounds (
grep+read) until the upstream fix lands
Changes
- add defensive validation for malformed result contexts
- treat drive-letter-only file paths with empty content as invalid output
- replace
Search failed: undefinedstyle output with a concrete fallback error message when the SDK does not provide an error string - add regression tests covering these cases
Example new error
Search returned malformed file contexts on Windows (for example `C` instead of a full file path).
This appears to be an upstream SDK Windows path parsing bug.
Temporary workaround: use `grep` + `read` for local code search until the SDK fix lands.
Validation
- added automated regression tests in
index.test.ts - verified that malformed Windows-style results no longer render as normal success output
- verified that missing SDK error strings no longer surface as
Search failed: undefined
Follow-up
A separate upstream fix is still needed in the SDK to correctly parse Windows file paths in finish-file handling.
Patch plan
1. Modify index.ts
Target area:
formatSearchResult(...)codebase_search.execute(...)
2. Add a small result validator
Introduce a helper like:
isMalformedContext(ctx)isMalformedResult(result)
Detection rules:
ctx.fileis only a drive letter likeCorDctx.contentis empty or uselessctx.lines === "*"- ideally require this on all or most returned contexts before declaring malformed
Important:
- do not try to reconstruct the real path
- just detect and fail clearly
3. Harden failure formatting
Right now the plugin can emit:
Search failed: undefined
Add a fallback so if:
!result.success- and
result.erroris empty or undefined
the plugin returns something like:
Search failed: search returned no error details.
4. Convert malformed “success” into explicit plugin failure
If the search says success: true but returns broken contexts like file: 'C', return a message like:
- malformed Windows search result
- likely upstream SDK bug
- workaround: use
grep+read
This should happen before normal formatting of <file path=...> output.
5. Add logging
In the malformed-result branch, log enough detail to help maintainers:
- number of contexts
- malformed file values
- maybe summary text if present
Not too noisy, just enough for diagnosis.
6. Add tests in index.test.ts
Add regression tests for:
- malformed result with
file: "C"returns actionable Windows error - missing SDK error string does not produce
Search failed: undefined - valid search results still format normally
Best test shape:
- mock or patch the search client prototype
- import plugin
- call
hooks.tool.codebase_search.execute(...) - assert returned text
7. Optional README note
Small note in README or changelog:
- malformed Windows search results are now detected and reported clearly
- root fix still depends on upstream SDK