From de6a58009ad875afd139441db90c5083141fd6eb Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Tue, 9 Dec 2025 14:16:28 +0000 Subject: [PATCH] fix: handle grep command errors and return user-friendly message for no matches --- Copilot/src/Tools/SearchWorkspaceTool.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Copilot/src/Tools/SearchWorkspaceTool.ts b/Copilot/src/Tools/SearchWorkspaceTool.ts index bc6bb8179b..9fb04b5d33 100644 --- a/Copilot/src/Tools/SearchWorkspaceTool.ts +++ b/Copilot/src/Tools/SearchWorkspaceTool.ts @@ -155,11 +155,23 @@ export class SearchWorkspaceTool extends StructuredTool { ".", ]; - return Execute.executeCommandFile({ - command: "grep", - args: finalArgs, - cwd, - }); + try { + return await Execute.executeCommandFile({ + command: "grep", + args: finalArgs, + cwd, + }); + } catch (error) { + // grep exits with code 1 when no matches are found - treat this as empty result + const errorMessage: string = (error as Error).message || ""; + if ( + errorMessage.includes("exit code 1") || + errorMessage.includes("Command failed") + ) { + return "No matches found"; + } + throw error; + } } /** Formats CLI output with context about scope and engine. */