Skip to content

Commit 7557178

Browse files
anandgupta42claude
andcommitted
fix: address CodeRabbit review — tighten error handling and add tests
- Add `AbortError` type check to catch block: only suppress errors that are AbortErrors AND from our timeout AND not user-initiated aborts - Add test for ENOENT propagation (non-abort errors not masked as timeout) - Add test for normal completion without timeout on small directories Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4042795 commit 7557178

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

packages/opencode/src/tool/glob.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export const GlobTool = Tool.define("glob", {
8383
})
8484
}
8585
} catch (err: any) {
86-
if (timeout.signal.aborted) {
86+
if (
87+
err?.name === "AbortError" &&
88+
timeout.signal.aborted &&
89+
!ctx.abort?.aborted
90+
) {
8791
// Our timeout fired — return partial results
8892
timedOut = true
8993
} else {

packages/opencode/test/tool/glob.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,39 @@ describe("tool.glob", () => {
197197
})
198198
})
199199

200+
test("propagates non-abort errors instead of treating as timeout", async () => {
201+
await using tmp = await tmpdir()
202+
await Instance.provide({
203+
directory: tmp.path,
204+
fn: async () => {
205+
const glob = await GlobTool.init()
206+
// Searching a non-existent path should throw ENOENT, not return "timed out"
207+
const badPath = path.join(tmp.path, "nonexistent-dir-12345")
208+
await expect(
209+
glob.execute({ pattern: "*.txt", path: badPath }, ctx),
210+
).rejects.toThrow()
211+
},
212+
})
213+
})
214+
215+
test("completes without timeout on small directories", async () => {
216+
await using tmp = await tmpdir({
217+
init: async (dir) => {
218+
await Bun.write(path.join(dir, "a.txt"), "hello")
219+
},
220+
})
221+
await Instance.provide({
222+
directory: tmp.path,
223+
fn: async () => {
224+
const glob = await GlobTool.init()
225+
const result = await glob.execute({ pattern: "*.txt" }, { ...ctx, abort: undefined })
226+
expect(result.metadata.count).toBe(1)
227+
expect(result.metadata.truncated).toBe(false)
228+
expect(result.output).not.toContain("timed out")
229+
},
230+
})
231+
})
232+
200233
test("excludes dist and build by default", async () => {
201234
await using tmp = await tmpdir({
202235
init: async (dir) => {

0 commit comments

Comments
 (0)