summaryrefslogtreecommitdiff
path: root/packages/cli/src/gemini.tsx
diff options
context:
space:
mode:
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[],