Skip to content

Commit dd3b79e

Browse files
committed
fix(core): handle Ctrl+C gracefully in configure-ai-agents
Add uncaughtException handler for ERR_USE_AFTER_CLOSE to prevent ugly stack trace when pressing Ctrl+C during enquirer prompts (Node 24 stricter readline behavior). Matches existing pattern used in nx init and create-nx-workspace.
1 parent d64e41d commit dd3b79e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/nx/src/command-line/configure-ai-agents/configure-ai-agents.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ export async function configureAiAgentsHandler(
6060
export async function configureAiAgentsHandlerImpl(
6161
options: ConfigureAiAgentsOptions
6262
): Promise<void> {
63+
// Node 24 has stricter readline behavior, and enquirer is not checking for closed state
64+
// when invoking operations, thus you get an ERR_USE_AFTER_CLOSE error.
65+
process.on('uncaughtException', (error) => {
66+
if (
67+
error &&
68+
typeof error === 'object' &&
69+
'code' in error &&
70+
error['code'] === 'ERR_USE_AFTER_CLOSE'
71+
)
72+
return;
73+
throw error;
74+
});
75+
6376
const normalizedOptions = normalizeOptions(options);
6477

6578
const {

0 commit comments

Comments
 (0)