From fe053c89000f262b2dd2251b28feed39e50a59f9 Mon Sep 17 00:00:00 2001 From: Giacomo Balli Date: Thu, 2 Apr 2026 12:00:05 -0700 Subject: [PATCH 1/2] fix: ensure CLI exits with non-zero code on errors Closes #540. Three fixes: 1. bin/cordova: call process.exit() explicitly after setting exitCode 2. src/cli.js: add unhandledRejection handler to catch unhandled promise rejections 3. src/cli.js: make printHelp() return its result so the promise chain works Co-Authored-By: Claude Opus 4.6 (1M context) --- bin/cordova | 1 + src/cli.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/bin/cordova b/bin/cordova index 6bd44e5c0..72f3106c1 100755 --- a/bin/cordova +++ b/bin/cordova @@ -37,4 +37,5 @@ cli(process.argv).catch(err => { // We cannot emit an error event here, as that would cause another error console.error(err.message); events.emit('verbose', err.stack); + process.exit(process.exitCode); }); diff --git a/src/cli.js b/src/cli.js index f74db7ea9..4a3a2da9d 100644 --- a/src/cli.js +++ b/src/cli.js @@ -140,6 +140,7 @@ module.exports = function (inputArgs) { function printHelp (command) { const result = help([command]); cordova.emit('results', result); + return result; } function cli (inputArgs) { @@ -154,6 +155,15 @@ function cli (inputArgs) { process.exit(1); }); + process.on('unhandledRejection', function (reason) { + const msg = reason instanceof Error ? reason.message : String(reason); + logger.error(msg); + if (reason instanceof Error) { + events.emit('verbose', reason.stack); + } + process.exit(1); + }); + logger.subscribe(events); if (args.silent) { From 718039ebaf07bbf395b878bb3532baa858df99c3 Mon Sep 17 00:00:00 2001 From: Giacomo Balli Date: Thu, 2 Apr 2026 17:57:09 -0700 Subject: [PATCH 2/2] remove process.exit() from bin/cordova catch handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process.exitCode is sufficient — Node will use it on graceful exit. process.exit() is a forceful synchronous exit that can truncate pending stdio writes and skip async cleanup. --- bin/cordova | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/cordova b/bin/cordova index 72f3106c1..6bd44e5c0 100755 --- a/bin/cordova +++ b/bin/cordova @@ -37,5 +37,4 @@ cli(process.argv).catch(err => { // We cannot emit an error event here, as that would cause another error console.error(err.message); events.emit('verbose', err.stack); - process.exit(process.exitCode); });