File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -381,18 +381,28 @@ export class MassargCommand<Args extends ArgsObject = ArgsObject>
381381 parent ?: MassargCommand < Args > ,
382382 ) : Promise < void > | void {
383383 // Set up process-level error handlers
384- const handleProcessError = ( error : Error ) => {
384+ const handleUncaught = ( error : Error ) => {
385+ cleanup ( )
385386 this . handleError ( error )
386387 }
387- process . on ( 'uncaughtException' , handleProcessError )
388- process . on ( 'unhandledRejection' , ( reason ) => {
388+ const handleRejection = ( reason : unknown ) => {
389+ cleanup ( )
389390 const error = reason instanceof Error ? reason : new Error ( String ( reason ) )
390- handleProcessError ( error )
391- } )
391+ this . handleError ( error )
392+ }
393+ const cleanup = ( ) => {
394+ process . off ( 'uncaughtException' , handleUncaught )
395+ process . off ( 'unhandledRejection' , handleRejection )
396+ }
397+
398+ process . on ( 'uncaughtException' , handleUncaught )
399+ process . on ( 'unhandledRejection' , handleRejection )
392400
393401 try {
394402 this . getArgs ( argv , args , parent , true )
403+ cleanup ( )
395404 } catch ( e ) {
405+ cleanup ( )
396406 this . handleError ( e )
397407 }
398408 }
You can’t perform that action at this time.
0 commit comments