File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ enum ExitCode {
2222 */
2323export async function main ( args : string [ ] ) : Promise < void > {
2424 try {
25+ // Setup global error handlers
26+ process . on ( "uncaughtException" , errorHandler ) ;
27+ process . on ( "unhandledRejection" , errorHandler ) ;
28+
29+ // Parse the command-line arguments
2530 let { help, version, options } = parseArgs ( args ) ;
2631
2732 if ( help ) {
@@ -51,13 +56,18 @@ async function bump(options: VersionBumpOptions): Promise<void> {
5156 await versionBump ( options ) ;
5257 }
5358 catch ( error ) {
54- let message = ( error as Error ) . message ;
59+ errorHandler ( error as Error ) ;
60+ }
61+ }
5562
56- if ( process . env . DEBUG || process . env . NODE_ENV === "development" ) {
57- message = ( error as Error ) . stack || message ;
58- }
5963
60- console . error ( message ) ;
61- process . exit ( ExitCode . RuntimeError ) ;
64+ function errorHandler ( error : Error ) : void {
65+ let message = error . message || String ( error ) ;
66+
67+ if ( process . env . DEBUG || process . env . NODE_ENV === "development" ) {
68+ message = error . stack || message ;
6269 }
70+
71+ console . error ( message ) ;
72+ process . exit ( ExitCode . FatalError ) ;
6373}
You can’t perform that action at this time.
0 commit comments