From 50d5cc2f6a4b3449fa70e7312ac9881b33124e85 Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Fri, 31 Oct 2025 17:00:28 +0800 Subject: [PATCH 1/2] fix: handle AbortError gracefully when loading commands --- .../src/services/FileCommandLoader.test.ts | 24 +++++++++++++++++++ .../cli/src/services/FileCommandLoader.ts | 6 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/services/FileCommandLoader.test.ts b/packages/cli/src/services/FileCommandLoader.test.ts index 7713775c..50c85e66 100644 --- a/packages/cli/src/services/FileCommandLoader.test.ts +++ b/packages/cli/src/services/FileCommandLoader.test.ts @@ -1227,4 +1227,28 @@ describe('FileCommandLoader', () => { expect(commands).toHaveLength(0); }); }); + + describe('AbortError handling', () => { + it('should silently ignore AbortError when operation is cancelled', async () => { + const userCommandsDir = Storage.getUserCommandsDir(); + mock({ + [userCommandsDir]: { + 'test1.toml': 'prompt = "Prompt 1"', + 'test2.toml': 'prompt = "Prompt 2"', + }, + }); + + const loader = new FileCommandLoader(null); + const controller = new AbortController(); + const signal = controller.signal; + + // Start loading and immediately abort + const loadPromise = loader.loadCommands(signal); + controller.abort(); + + // Should not throw or print errors + const commands = await loadPromise; + expect(commands).toHaveLength(0); + }); + }); }); diff --git a/packages/cli/src/services/FileCommandLoader.ts b/packages/cli/src/services/FileCommandLoader.ts index fe485fa2..5527aa80 100644 --- a/packages/cli/src/services/FileCommandLoader.ts +++ b/packages/cli/src/services/FileCommandLoader.ts @@ -120,7 +120,11 @@ export class FileCommandLoader implements ICommandLoader { // Add all commands without deduplication allCommands.push(...commands); } catch (error) { - if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { + // Ignore ENOENT (directory doesn't exist) and AbortError (operation was cancelled) + const isEnoent = (error as NodeJS.ErrnoException).code === 'ENOENT'; + const isAbortError = + error instanceof Error && error.name === 'AbortError'; + if (!isEnoent && !isAbortError) { console.error( `[FileCommandLoader] Error loading commands from ${dirInfo.path}:`, error, From 448e30bf88ed650e6fd68e0aa1820b111c1fd20b Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Wed, 5 Nov 2025 16:06:35 +0800 Subject: [PATCH 2/2] feat: support custom working directory for child process in start.js --- scripts/start.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/start.js b/scripts/start.js index 9898d0be..baa9fd98 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -69,7 +69,14 @@ if (process.env.DEBUG) { // than the relaunched process making it harder to debug. env.GEMINI_CLI_NO_RELAUNCH = 'true'; } -const child = spawn('node', nodeArgs, { stdio: 'inherit', env }); +// Use process.cwd() to inherit the working directory from launch.json cwd setting +// This allows debugging from a specific directory (e.g., .todo) +const workingDir = process.env.QWEN_WORKING_DIR || process.cwd(); +const child = spawn('node', nodeArgs, { + stdio: 'inherit', + env, + cwd: workingDir, +}); child.on('close', (code) => { process.exit(code);