fix: ensure CLI exits with non-zero code on errors#694
fix: ensure CLI exits with non-zero code on errors#694BigBalli wants to merge 2 commits intoapache:masterfrom
Conversation
Closes apache#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) <noreply@anthropic.com>
This doesn't really make sense. process.exit is a forceful synchronous exit. It will not wait for pending asynchronous tasks including stdio writes. The more "proper" way to exit node is to set
So introducing |
|
Oh right, that makes sense... |
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #694 +/- ##
==========================================
+ Coverage 72.90% 73.33% +0.43%
==========================================
Files 3 3
Lines 620 630 +10
==========================================
+ Hits 452 462 +10
Misses 168 168 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
breautek
left a comment
There was a problem hiding this comment.
Thanks for taking the time to respond to the criticism and improving the PR.
This looks good to me, I think using process.exit is terrible in error situations, and it's already used in uncaughtException.
breautek
left a comment
There was a problem hiding this comment.
on commit fe053c8 can you amend the commit to include a line "Generated-by: Claude"
This is to satisfy Apache AI policy
When providing contributions authored using generative AI tooling, a recommended practice is for contributors to indicate the tooling used to create the contribution. This should be included as a token in the source control commit message, for example including the phrase “Generated-by: ”. This allows for future release tooling to be considered that pulls this content into a machine parsable Tooling-Provenance file.
Summary
Fixes the CLI silently exiting with code 0 when errors occur as unhandled rejections.
Changes:
src/cli.js: AddunhandledRejectionhandler so rejected promises that bypass thebin/cordova.catch()are caught and exit with code 1 (mirrors the existinguncaughtExceptionhandler)src/cli.js: Return result fromprintHelp()so the promise chain resolves with the help textbin/cordova: No changes to the existing.catch()—process.exitCodeis the correct mechanism for graceful exitTest plan
cordova buildwith invalid platform — verify non-zero exit codecordova help— verify output is printed and process exits cleanly