diff --git a/packages/prompts/src/index.ts b/packages/prompts/src/index.ts index 9e67044..eafc383 100644 --- a/packages/prompts/src/index.ts +++ b/packages/prompts/src/index.ts @@ -642,22 +642,17 @@ export const spinner = () => { unblock(); }; - const handleExit = (code: number) => { - if (isSpinnerActive) { - stop(code > 1 ? 'Something went wrong' : 'Canceled', code); - } + const handleExit = (code: number, error?: unknown) => { + const message = code > 1 ? 'Something went wrong' : 'Canceled'; + if (isSpinnerActive) stop(message, code); + if (error) console.error(error); }; - /** - * Signal Events: https://nodejs.org/api/process.html#signal-events - * `uncaughtException`: Trigger on uncaught code exception - * `unhandledRejection`: Trigger on unhandled promise rejection - * `SIGINT`: Trigger on Ctrl + C. PS: it will not trigger while terminal raw mode is enabled - * `SIGTERM`: Trigger on kill process - * `exit`: Trigger on exit - */ - process.on('uncaughtException', () => handleExit(2)); - process.on('unhandledRejection', () => handleExit(2)); + // Reference: https://nodejs.org/api/process.html#event-uncaughtexception + process.on('uncaughtException', (error) => handleExit(2, error)); + // Reference: https://nodejs.org/api/process.html#event-unhandledrejection + process.on('unhandledRejection', (error) => handleExit(2, error)); + // Reference Signal Events: https://nodejs.org/api/process.html#signal-events process.on('SIGINT', () => handleExit(1)); process.on('SIGTERM', () => handleExit(1)); process.on('exit', handleExit);