diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index 4735f416f..a76a2fdc4 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -91,7 +91,26 @@ export function shouldShowExitMessage(): boolean { // Add global error handlers to prevent uncaught errors from crashing the process process.on("unhandledRejection", (reason, promise) => { - logger.error("Unhandled Rejection at:", { promise, reason }); + // Extract useful information from the reason + const errorDetails = { + promiseString: String(promise), + reasonType: typeof reason, + reasonConstructor: reason?.constructor?.name, + }; + + // If reason is an Error, use it directly for better stack traces + if (reason instanceof Error) { + logger.error("Unhandled Promise Rejection", reason, errorDetails); + } else { + // Convert non-Error reasons to Error for consistent handling + const error = new Error(`Unhandled rejection: ${String(reason)}`); + logger.error("Unhandled Promise Rejection", error, { + ...errorDetails, + originalReason: String(reason), + }); + } + + // Sentry capture remains the same sentryService.captureException( reason instanceof Error ? reason : new Error(String(reason)), { diff --git a/extensions/cli/src/util/logger.ts b/extensions/cli/src/util/logger.ts index 8f32e67fe..69a672c65 100644 --- a/extensions/cli/src/util/logger.ts +++ b/extensions/cli/src/util/logger.ts @@ -44,6 +44,19 @@ function createReplacer() { seen.add(value); } + // Handle Error objects explicitly - extract useful properties + if (value instanceof Error) { + const errorObj: any = { + name: value.name, + message: value.message, + stack: value.stack, + }; + if (value.cause) { + errorObj.cause = value.cause; + } + return errorObj; + } + // Handle functions if (typeof value === "function") { return "[Function]";