@@ -98,7 +98,7 @@ export class ToolRunner extends events.EventEmitter {
98
98
if ( c !== '"' ) {
99
99
arg += '\\' ;
100
100
} else {
101
- arg . slice ( 0 , - 1 ) ;
101
+ arg . slice ( 0 , - 1 ) ;
102
102
}
103
103
}
104
104
arg += c ;
@@ -174,7 +174,7 @@ export class ToolRunner extends events.EventEmitter {
174
174
// Windows (regular)
175
175
else {
176
176
commandParts . push ( this . _windowsQuoteCmdArg ( toolPath ) ) ;
177
- commandParts = commandParts . concat ( args . map ( arg => this . _windowsQuoteCmdArg ( arg ) ) ) ;
177
+ commandParts = commandParts . concat ( args . map ( arg => this . _windowsQuoteCmdArg ( arg ) ) ) ;
178
178
}
179
179
}
180
180
else {
@@ -333,7 +333,7 @@ export class ToolRunner extends events.EventEmitter {
333
333
return args ;
334
334
}
335
335
} else if ( options . shell ) {
336
- return this . args . map ( arg => {
336
+ return this . args . map ( arg => {
337
337
if ( this . _isWrapped ( arg , "'" ) ) {
338
338
return arg ;
339
339
}
@@ -636,7 +636,7 @@ export class ToolRunner extends events.EventEmitter {
636
636
this . _getSpawnArgs ( optionsNonNull ) ,
637
637
this . _getSpawnOptions ( optionsNonNull ) ) ;
638
638
639
- waitingEvents ++ ;
639
+ waitingEvents ++ ;
640
640
cp = child . spawn (
641
641
pipeOutputToTool . _getSpawnFileName ( optionsNonNull ) ,
642
642
pipeOutputToTool . _getSpawnArgs ( optionsNonNull ) ,
@@ -650,7 +650,7 @@ export class ToolRunner extends events.EventEmitter {
650
650
fileStream . on ( 'finish' , ( ) => {
651
651
waitingEvents -- ; //file write is complete
652
652
fileStream = null ;
653
- if ( waitingEvents == 0 ) {
653
+ if ( waitingEvents == 0 ) {
654
654
if ( error ) {
655
655
reject ( error ) ;
656
656
} else {
@@ -662,7 +662,7 @@ export class ToolRunner extends events.EventEmitter {
662
662
waitingEvents -- ; //there were errors writing to the file, write is done
663
663
this . _debug ( `Failed to pipe output of ${ toolPathFirst } to file ${ this . pipeOutputToFile } . Error = ${ err } ` ) ;
664
664
fileStream = null ;
665
- if ( waitingEvents == 0 ) {
665
+ if ( waitingEvents == 0 ) {
666
666
if ( error ) {
667
667
reject ( error ) ;
668
668
} else {
@@ -671,7 +671,7 @@ export class ToolRunner extends events.EventEmitter {
671
671
}
672
672
} ) ;
673
673
}
674
-
674
+
675
675
//pipe stdout of first tool to stdin of second tool
676
676
cpFirst . stdout ?. on ( 'data' , ( data : Buffer ) => {
677
677
try {
@@ -703,7 +703,7 @@ export class ToolRunner extends events.EventEmitter {
703
703
}
704
704
cp . stdin ?. end ( ) ;
705
705
error = new Error ( toolPathFirst + ' failed. ' + err . message ) ;
706
- if ( waitingEvents == 0 ) {
706
+ if ( waitingEvents == 0 ) {
707
707
reject ( error ) ;
708
708
}
709
709
} ) ;
@@ -719,77 +719,77 @@ export class ToolRunner extends events.EventEmitter {
719
719
fileStream . end ( ) ;
720
720
}
721
721
cp . stdin ?. end ( ) ;
722
- if ( waitingEvents == 0 ) {
722
+ if ( waitingEvents == 0 ) {
723
723
if ( error ) {
724
724
reject ( error ) ;
725
725
} else {
726
726
resolve ( returnCode ) ;
727
727
}
728
728
}
729
729
} ) ;
730
-
730
+
731
731
var stdbuffer : string = '' ;
732
732
cp . stdout ?. on ( 'data' , ( data : Buffer ) => {
733
733
this . emit ( 'stdout' , data ) ;
734
-
734
+
735
735
if ( ! optionsNonNull . silent ) {
736
736
optionsNonNull . outStream ! . write ( data ) ;
737
737
}
738
-
738
+
739
739
this . _processLineBuffer ( data , stdbuffer , ( line : string ) => {
740
740
this . emit ( 'stdline' , line ) ;
741
741
} ) ;
742
742
} ) ;
743
-
743
+
744
744
var errbuffer : string = '' ;
745
745
cp . stderr ?. on ( 'data' , ( data : Buffer ) => {
746
746
this . emit ( 'stderr' , data ) ;
747
-
747
+
748
748
success = ! optionsNonNull . failOnStdErr ;
749
749
if ( ! optionsNonNull . silent ) {
750
750
var s = optionsNonNull . failOnStdErr ? optionsNonNull . errStream ! : optionsNonNull . outStream ! ;
751
751
s . write ( data ) ;
752
752
}
753
-
753
+
754
754
this . _processLineBuffer ( data , errbuffer , ( line : string ) => {
755
755
this . emit ( 'errline' , line ) ;
756
756
} ) ;
757
757
} ) ;
758
-
758
+
759
759
cp . on ( 'error' , ( err : Error ) => {
760
760
waitingEvents -- ; //process is done with errors
761
761
error = new Error ( toolPath + ' failed. ' + err . message ) ;
762
- if ( waitingEvents == 0 ) {
762
+ if ( waitingEvents == 0 ) {
763
763
reject ( error ) ;
764
764
}
765
765
} ) ;
766
-
766
+
767
767
cp . on ( 'close' , ( code : number , signal : any ) => {
768
768
waitingEvents -- ; //process is complete
769
769
this . _debug ( 'rc:' + code ) ;
770
770
returnCode = code ;
771
-
771
+
772
772
if ( stdbuffer . length > 0 ) {
773
773
this . emit ( 'stdline' , stdbuffer ) ;
774
774
}
775
-
775
+
776
776
if ( errbuffer . length > 0 ) {
777
777
this . emit ( 'errline' , errbuffer ) ;
778
778
}
779
-
779
+
780
780
if ( code != 0 && ! optionsNonNull . ignoreReturnCode ) {
781
781
success = false ;
782
782
}
783
-
783
+
784
784
this . _debug ( 'success:' + success ) ;
785
-
785
+
786
786
if ( ! successFirst ) { //in the case output is piped to another tool, check exit code of both tools
787
787
error = new Error ( toolPathFirst + ' failed with return code: ' + returnCodeFirst ) ;
788
788
} else if ( ! success ) {
789
789
error = new Error ( toolPath + ' failed with return code: ' + code ) ;
790
790
}
791
-
792
- if ( waitingEvents == 0 ) {
791
+
792
+ if ( waitingEvents == 0 ) {
793
793
if ( error ) {
794
794
reject ( error ) ;
795
795
} else {
@@ -838,7 +838,7 @@ export class ToolRunner extends events.EventEmitter {
838
838
this . _getSpawnArgs ( optionsNonNull ) ,
839
839
this . _getSpawnOptions ( optionsNonNull ) ) ;
840
840
841
- waitingEvents ++ ;
841
+ waitingEvents ++ ;
842
842
cp = child . spawn (
843
843
pipeOutputToTool . _getSpawnFileName ( optionsNonNull ) ,
844
844
pipeOutputToTool . _getSpawnArgs ( optionsNonNull ) ,
@@ -850,7 +850,7 @@ export class ToolRunner extends events.EventEmitter {
850
850
fileStream . on ( 'finish' , ( ) => {
851
851
waitingEvents -- ; //file write is complete
852
852
fileStream = null ;
853
- if ( waitingEvents == 0 ) {
853
+ if ( waitingEvents == 0 ) {
854
854
if ( error ) {
855
855
defer . reject ( error ) ;
856
856
} else {
@@ -862,7 +862,7 @@ export class ToolRunner extends events.EventEmitter {
862
862
waitingEvents -- ; //there were errors writing to the file, write is done
863
863
this . _debug ( `Failed to pipe output of ${ toolPathFirst } to file ${ this . pipeOutputToFile } . Error = ${ err } ` ) ;
864
864
fileStream = null ;
865
- if ( waitingEvents == 0 ) {
865
+ if ( waitingEvents == 0 ) {
866
866
if ( error ) {
867
867
defer . reject ( error ) ;
868
868
} else {
@@ -901,7 +901,7 @@ export class ToolRunner extends events.EventEmitter {
901
901
}
902
902
cp . stdin ?. end ( ) ;
903
903
error = new Error ( toolPathFirst + ' failed. ' + err . message ) ;
904
- if ( waitingEvents == 0 ) {
904
+ if ( waitingEvents == 0 ) {
905
905
defer . reject ( error ) ;
906
906
}
907
907
} ) ;
@@ -917,7 +917,7 @@ export class ToolRunner extends events.EventEmitter {
917
917
fileStream . end ( ) ;
918
918
}
919
919
cp . stdin ?. end ( ) ;
920
- if ( waitingEvents == 0 ) {
920
+ if ( waitingEvents == 0 ) {
921
921
if ( error ) {
922
922
defer . reject ( error ) ;
923
923
} else {
@@ -957,7 +957,7 @@ export class ToolRunner extends events.EventEmitter {
957
957
cp . on ( 'error' , ( err : Error ) => {
958
958
waitingEvents -- ; //process is done with errors
959
959
error = new Error ( toolPath + ' failed. ' + err . message ) ;
960
- if ( waitingEvents == 0 ) {
960
+ if ( waitingEvents == 0 ) {
961
961
defer . reject ( error ) ;
962
962
}
963
963
} ) ;
@@ -987,7 +987,7 @@ export class ToolRunner extends events.EventEmitter {
987
987
error = new Error ( toolPath + ' failed with return code: ' + code ) ;
988
988
}
989
989
990
- if ( waitingEvents == 0 ) {
990
+ if ( waitingEvents == 0 ) {
991
991
if ( error ) {
992
992
defer . reject ( error ) ;
993
993
} else {
@@ -1107,15 +1107,15 @@ export class ToolRunner extends events.EventEmitter {
1107
1107
if ( stdbuffer . length > 0 ) {
1108
1108
this . emit ( 'stdline' , stdbuffer ) ;
1109
1109
}
1110
-
1110
+
1111
1111
if ( errbuffer . length > 0 ) {
1112
1112
this . emit ( 'errline' , errbuffer ) ;
1113
1113
}
1114
-
1114
+
1115
1115
if ( cp ) {
1116
1116
cp . removeAllListeners ( ) ;
1117
1117
}
1118
-
1118
+
1119
1119
if ( error ) {
1120
1120
reject ( error ) ;
1121
1121
}
@@ -1182,18 +1182,19 @@ export class ToolRunner extends events.EventEmitter {
1182
1182
state . CheckComplete ( ) ;
1183
1183
} ) ;
1184
1184
1185
- cp . on ( 'exit' , ( code : number , signal : number | NodeJS . Signals ) => {
1185
+ // Do not write debug logs here. Sometimes stdio not closed yet and you can damage user output commands.
1186
+ cp . on ( 'exit' , ( code : number | null , signal : NodeJS . Signals | null ) => {
1186
1187
state . processExitCode = code ;
1188
+ state . processExitSignal = signal ;
1187
1189
state . processExited = true ;
1188
- this . _debug ( `STDIO streams have closed and received exit code ${ code } and signal ${ signal } for tool '${ this . toolPath } '` ) ;
1189
1190
state . CheckComplete ( )
1190
1191
} ) ;
1191
1192
1192
- cp . on ( 'close' , ( code : number , signal : number | NodeJS . Signals ) => {
1193
- state . processExitCode = code ;
1194
- state . processExited = true ;
1193
+ cp . on ( 'close' , ( code : number | null , signal : NodeJS . Signals | null ) => {
1194
+ state . processCloseCode = code ;
1195
+ state . processCloseSignal = signal ;
1195
1196
state . processClosed = true ;
1196
- this . _debug ( `STDIO streams have closed and received exit code ${ code } and signal ${ signal } for tool ' ${ this . toolPath } '` ) ;
1197
+ state . processExited = true ;
1197
1198
state . CheckComplete ( ) ;
1198
1199
} ) ;
1199
1200
@@ -1314,18 +1315,19 @@ export class ToolRunner extends events.EventEmitter {
1314
1315
state . CheckComplete ( ) ;
1315
1316
} ) ;
1316
1317
1317
- cp . on ( 'exit' , ( code : number , signal : number | NodeJS . Signals ) => {
1318
+ // Do not write debug logs here. Sometimes stdio not closed yet and you can damage user output commands.
1319
+ cp . on ( 'exit' , ( code : number | null , signal : NodeJS . Signals | null ) => {
1318
1320
state . processExitCode = code ;
1321
+ state . processExitSignal = signal ;
1319
1322
state . processExited = true ;
1320
- this . _debug ( `STDIO streams have closed and received exit code ${ code } and signal ${ signal } for tool '${ this . toolPath } '` ) ;
1321
1323
state . CheckComplete ( )
1322
1324
} ) ;
1323
1325
1324
- cp . on ( 'close' , ( code : number , signal : number | NodeJS . Signals ) => {
1325
- state . processExitCode = code ;
1326
- state . processExited = true ;
1326
+ cp . on ( 'close' , ( code : number | null , signal : NodeJS . Signals | null ) => {
1327
+ state . processCloseCode = code ;
1328
+ state . processCloseSignal = signal ;
1327
1329
state . processClosed = true ;
1328
- this . _debug ( `STDIO streams have closed and received exit code ${ code } and signal ${ signal } for tool ' ${ this . toolPath } '` ) ;
1330
+ state . processExited = true ;
1329
1331
state . CheckComplete ( ) ;
1330
1332
} ) ;
1331
1333
@@ -1404,15 +1406,22 @@ class ExecState extends events.EventEmitter {
1404
1406
}
1405
1407
1406
1408
processClosed : boolean ; // tracks whether the process has exited and stdio is closed
1407
- processError : string ;
1408
- processExitCode : number ;
1409
+ processCloseCode : number | null ;
1410
+ processCloseSignal : NodeJS . Signals | null ;
1411
+
1409
1412
processExited : boolean ; // tracks whether the process has exited
1413
+ processExitCode : number | null ;
1414
+ processExitSignal : NodeJS . Signals | null ;
1415
+
1416
+ processError : string ;
1410
1417
processStderr : boolean ; // tracks whether stderr was written to
1411
- private delay = 10000 ; // 10 seconds
1412
- private done : boolean ;
1413
- private options : IExecOptions ;
1418
+
1419
+ private readonly delay : number = 10000 ; // 10 seconds
1420
+ private readonly options : IExecOptions ;
1421
+ private readonly toolPath : string ;
1422
+
1414
1423
private timeout : NodeJS . Timer | null = null ;
1415
- private toolPath : string ;
1424
+ private done : boolean ;
1416
1425
1417
1426
public CheckComplete ( ) : void {
1418
1427
if ( this . done ) {
@@ -1435,6 +1444,8 @@ class ExecState extends events.EventEmitter {
1435
1444
// determine whether there is an error
1436
1445
let error : Error | undefined ;
1437
1446
if ( this . processExited ) {
1447
+ this . _debug ( `Process exited with code ${ this . processExitCode } and signal ${ this . processExitSignal } for tool '${ this . toolPath } '` ) ;
1448
+
1438
1449
if ( this . processError ) {
1439
1450
error = new Error ( im . _loc ( 'LIB_ProcessError' , this . toolPath , this . processError ) ) ;
1440
1451
}
@@ -1446,6 +1457,10 @@ class ExecState extends events.EventEmitter {
1446
1457
}
1447
1458
}
1448
1459
1460
+ if ( this . processClosed ) {
1461
+ this . _debug ( `STDIO streams have closed and received exit code ${ this . processCloseCode } and signal ${ this . processCloseSignal } for tool '${ this . toolPath } '` ) ;
1462
+ }
1463
+
1449
1464
// clear the timeout
1450
1465
if ( this . timeout ) {
1451
1466
clearTimeout ( this . timeout ) ;
0 commit comments