From 0db03159d5ba91a42322ff6e421f7f1ecf856c0f Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 26 Mar 2025 11:08:46 +0800 Subject: [PATCH 1/4] fix: extension uncaughtException listen Maximum call stack size exceeded --- src/vs/workbench/api/node/extensionHostProcess.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/api/node/extensionHostProcess.ts b/src/vs/workbench/api/node/extensionHostProcess.ts index feaece95534e..509a8723620e 100644 --- a/src/vs/workbench/api/node/extensionHostProcess.ts +++ b/src/vs/workbench/api/node/extensionHostProcess.ts @@ -102,8 +102,9 @@ function patchProcess(allowExit: boolean) { process.env['ELECTRON_RUN_AS_NODE'] = '1'; process.on = function (event: string, listener: (...args: any[]) => void) { + let newListener = listener if (event === 'uncaughtException') { - listener = function () { + newListener = function () { try { return listener.call(undefined, arguments); } catch { @@ -114,7 +115,7 @@ function patchProcess(allowExit: boolean) { } }; } - nativeOn(event, listener); + nativeOn(event, newListener); }; } From 0aba28a66ba9a1949f8394f8baf241fefe033eeb Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 26 Mar 2025 11:23:07 +0800 Subject: [PATCH 2/4] fix: use apply for arguments --- src/vs/workbench/api/node/extensionHostProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/api/node/extensionHostProcess.ts b/src/vs/workbench/api/node/extensionHostProcess.ts index 509a8723620e..360996eb5457 100644 --- a/src/vs/workbench/api/node/extensionHostProcess.ts +++ b/src/vs/workbench/api/node/extensionHostProcess.ts @@ -106,7 +106,7 @@ function patchProcess(allowExit: boolean) { if (event === 'uncaughtException') { newListener = function () { try { - return listener.call(undefined, arguments); + return listener.apply(undefined, (arguments as unknown as any[])); } catch { // DO NOT HANDLE NOR PRINT the error here because this can and will lead to // more errors which will cause error handling to be reentrant and eventually From 01af033a87545c032b077c0a238807ec8080ac39 Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 26 Mar 2025 13:55:53 +0800 Subject: [PATCH 3/4] style: lint --- src/vs/workbench/api/node/extensionHostProcess.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/api/node/extensionHostProcess.ts b/src/vs/workbench/api/node/extensionHostProcess.ts index 360996eb5457..2ad6adf7bdd1 100644 --- a/src/vs/workbench/api/node/extensionHostProcess.ts +++ b/src/vs/workbench/api/node/extensionHostProcess.ts @@ -102,7 +102,7 @@ function patchProcess(allowExit: boolean) { process.env['ELECTRON_RUN_AS_NODE'] = '1'; process.on = function (event: string, listener: (...args: any[]) => void) { - let newListener = listener + let newListener = listener; if (event === 'uncaughtException') { newListener = function () { try { From 0bbb355577e0b2200ddd30588e2b88d50e4b4a05 Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 26 Mar 2025 09:40:31 +0100 Subject: [PATCH 4/4] :lipstick: --- src/vs/workbench/api/node/extensionHostProcess.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/api/node/extensionHostProcess.ts b/src/vs/workbench/api/node/extensionHostProcess.ts index 2ad6adf7bdd1..704a0dbb5bd6 100644 --- a/src/vs/workbench/api/node/extensionHostProcess.ts +++ b/src/vs/workbench/api/node/extensionHostProcess.ts @@ -102,11 +102,11 @@ function patchProcess(allowExit: boolean) { process.env['ELECTRON_RUN_AS_NODE'] = '1'; process.on = function (event: string, listener: (...args: any[]) => void) { - let newListener = listener; if (event === 'uncaughtException') { - newListener = function () { + const actualListener = listener; + listener = function (...args: any[]) { try { - return listener.apply(undefined, (arguments as unknown as any[])); + return actualListener.apply(undefined, args); } catch { // DO NOT HANDLE NOR PRINT the error here because this can and will lead to // more errors which will cause error handling to be reentrant and eventually @@ -115,7 +115,7 @@ function patchProcess(allowExit: boolean) { } }; } - nativeOn(event, newListener); + nativeOn(event, listener); }; }