summaryrefslogtreecommitdiff
path: root/packages/cli/src/gemini.tsx
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-07-25 17:35:26 -0700
committerGitHub <[email protected]>2025-07-26 00:35:26 +0000
commit21fef1620d78f07af01a75b8bbbeeb15798e73ef (patch)
tree751591161eb9d65f6d776152dadf8183a39a8179 /packages/cli/src/gemini.tsx
parentfb751c542bc935158aaa0d01c0694eb3bb6b2919 (diff)
Handle unhandled rejections more gracefully. (#4417)
Co-authored-by: Tommaso Sciortino <[email protected]>
Diffstat (limited to 'packages/cli/src/gemini.tsx')
-rw-r--r--packages/cli/src/gemini.tsx39
1 files changed, 24 insertions, 15 deletions
diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx
index 2023431f..c771fb95 100644
--- a/packages/cli/src/gemini.tsx
+++ b/packages/cli/src/gemini.tsx
@@ -40,6 +40,7 @@ import {
import { validateAuthMethod } from './config/auth.js';
import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js';
import { validateNonInteractiveAuth } from './validateNonInterActiveAuth.js';
+import { appEvents, AppEvent } from './utils/events.js';
function getNodeMemoryArgs(config: Config): string[] {
const totalMemoryMB = os.totalmem() / (1024 * 1024);
@@ -86,7 +87,30 @@ async function relaunchWithAdditionalArgs(additionalArgs: string[]) {
}
import { runAcpPeer } from './acp/acpPeer.js';
+export function setupUnhandledRejectionHandler() {
+ let unhandledRejectionOccurred = false;
+ process.on('unhandledRejection', (reason, _promise) => {
+ const errorMessage = `=========================================
+This is an unexpected error. Please file a bug report using the /bug tool.
+CRITICAL: Unhandled Promise Rejection!
+=========================================
+Reason: ${reason}${
+ reason instanceof Error && reason.stack
+ ? `
+Stack trace:
+${reason.stack}`
+ : ''
+ }`;
+ appEvents.emit(AppEvent.LogError, errorMessage);
+ if (!unhandledRejectionOccurred) {
+ unhandledRejectionOccurred = true;
+ appEvents.emit(AppEvent.OpenDebugConsole);
+ }
+ });
+}
+
export async function main() {
+ setupUnhandledRejectionHandler();
const workspaceRoot = process.cwd();
const settings = loadSettings(workspaceRoot);
@@ -272,21 +296,6 @@ function setWindowTitle(title: string, settings: LoadedSettings) {
}
}
-// --- Global Unhandled Rejection Handler ---
-process.on('unhandledRejection', (reason, _promise) => {
- // Log other unexpected unhandled rejections as critical errors
- console.error('=========================================');
- console.error('CRITICAL: Unhandled Promise Rejection!');
- console.error('=========================================');
- console.error('Reason:', reason);
- console.error('Stack trace may follow:');
- if (!(reason instanceof Error)) {
- console.error(reason);
- }
- // Exit for genuinely unhandled errors
- process.exit(1);
-});
-
async function loadNonInteractiveConfig(
config: Config,
extensions: Extension[],