File tree 2 files changed +53
-2
lines changed
2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,16 @@ const killExecaProcess = async (execaProcess) => {
54
54
try {
55
55
const childPids = await pidTree ( execaProcess . pid )
56
56
for ( const childPid of childPids ) {
57
- process . kill ( childPid )
57
+ try {
58
+ process . kill ( childPid )
59
+ } catch ( error ) {
60
+ debugLog ( `Failed to kill process with pid "%d": %o` , childPid , error )
61
+ }
58
62
}
59
63
} catch ( error ) {
60
64
// Suppress "No matching pid found" error. This probably means
61
65
// the process already died before executing.
62
- debugLog ( `Failed to find process for pid %d ` , execaProcess . pid )
66
+ debugLog ( `Failed to kill process with pid "%d": %o ` , execaProcess . pid , error )
63
67
}
64
68
65
69
// The execa process is killed separately in order to get the `KILLED` status.
Original file line number Diff line number Diff line change @@ -484,4 +484,51 @@ describe('resolveTaskFn', () => {
484
484
value : realKill ,
485
485
} )
486
486
} )
487
+
488
+ it ( 'should ignore error when trying to kill child processes' , async ( ) => {
489
+ expect . assertions ( 3 )
490
+
491
+ execa . mockImplementationOnce ( ( ) =>
492
+ createExecaReturnValue (
493
+ {
494
+ stdout : 'a-ok' ,
495
+ stderr : '' ,
496
+ code : 0 ,
497
+ cmd : 'mock cmd' ,
498
+ failed : false ,
499
+ killed : false ,
500
+ signal : null ,
501
+ } ,
502
+ 1000
503
+ )
504
+ )
505
+
506
+ const realKill = process . kill
507
+ const mockKill = jest . fn ( ( ) => {
508
+ throw new Error ( 'kill ESRCH' )
509
+ } )
510
+ Object . defineProperty ( process , 'kill' , {
511
+ value : mockKill ,
512
+ } )
513
+
514
+ pidTree . mockImplementationOnce ( ( ) => [ '1234' ] )
515
+
516
+ const taskFn = resolveTaskFn ( { command : 'node' } )
517
+
518
+ const context = getInitialState ( )
519
+ const taskPromise = taskFn ( context )
520
+
521
+ context . events . emit ( 'lint-staged:taskError' )
522
+
523
+ jest . runAllTimers ( )
524
+
525
+ await expect ( taskPromise ) . rejects . toThrowErrorMatchingInlineSnapshot ( `"node [KILLED]"` )
526
+
527
+ expect ( mockKill ) . toHaveBeenCalledTimes ( 1 )
528
+ expect ( mockKill ) . toHaveBeenCalledWith ( '1234' )
529
+
530
+ Object . defineProperty ( process , 'kill' , {
531
+ value : realKill ,
532
+ } )
533
+ } )
487
534
} )
You can’t perform that action at this time.
0 commit comments