@@ -9,7 +9,6 @@ import { getOptionalInput, isAnalyzingDefaultBranch } from "./actions-util";
9
9
import * as api from "./api-client" ;
10
10
import type { Config } from "./config-utils" ;
11
11
import { EnvVar } from "./environment" ;
12
- import { errorMatchers } from "./error-matcher" ;
13
12
import {
14
13
CODEQL_VERSION_NEW_ANALYSIS_SUMMARY ,
15
14
CodeQLDefaultVersionInfo ,
@@ -20,7 +19,6 @@ import {
20
19
import { isTracedLanguage , Language } from "./languages" ;
21
20
import { Logger } from "./logging" ;
22
21
import * as setupCodeql from "./setup-codeql" ;
23
- import { toolrunnerErrorCatcher } from "./toolrunner-error-catcher" ;
24
22
import * as util from "./util" ;
25
23
import { wrapError } from "./util" ;
26
24
@@ -627,19 +625,15 @@ export async function getCodeQLForCmd(
627
625
`autobuild${ ext } `
628
626
) ;
629
627
// Run trace command
630
- await toolrunnerErrorCatcher (
631
- cmd ,
632
- [
633
- "database" ,
634
- "trace-command" ,
635
- ...( await getTrapCachingExtractorConfigArgsForLang ( config , language ) ) ,
636
- ...getExtraOptionsFromEnv ( [ "database" , "trace-command" ] ) ,
637
- databasePath ,
638
- "--" ,
639
- traceCommand ,
640
- ] ,
641
- errorMatchers
642
- ) ;
628
+ await runTool ( cmd , [
629
+ "database" ,
630
+ "trace-command" ,
631
+ ...( await getTrapCachingExtractorConfigArgsForLang ( config , language ) ) ,
632
+ ...getExtraOptionsFromEnv ( [ "database" , "trace-command" ] ) ,
633
+ databasePath ,
634
+ "--" ,
635
+ traceCommand ,
636
+ ] ) ;
643
637
} ,
644
638
async finalizeDatabase (
645
639
databasePath : string ,
@@ -782,7 +776,7 @@ export async function getCodeQLForCmd(
782
776
if ( querySuitePath ) {
783
777
codeqlArgs . push ( querySuitePath ) ;
784
778
}
785
- await toolrunnerErrorCatcher ( cmd , codeqlArgs , errorMatchers ) ;
779
+ await runTool ( cmd , codeqlArgs ) ;
786
780
} ,
787
781
async databaseInterpretResults (
788
782
databasePath : string ,
@@ -848,17 +842,13 @@ export async function getCodeQLForCmd(
848
842
codeqlArgs . push ( ...querySuitePaths ) ;
849
843
}
850
844
// capture stdout, which contains analysis summaries
851
- const returnState = await toolrunnerErrorCatcher (
852
- cmd ,
853
- codeqlArgs ,
854
- errorMatchers
855
- ) ;
845
+ const returnState = await runTool ( cmd , codeqlArgs ) ;
856
846
857
847
if ( shouldWorkaroundInvalidNotifications ) {
858
848
util . fixInvalidNotificationsInFile ( codeqlOutputFile , sarifFile , logger ) ;
859
849
}
860
850
861
- return returnState . stdout ;
851
+ return returnState ;
862
852
} ,
863
853
async databasePrintBaseline ( databasePath : string ) : Promise < string > {
864
854
const codeqlArgs = [
@@ -1161,11 +1151,34 @@ async function runTool(
1161
1151
ignoreReturnCode : true ,
1162
1152
...( opts . stdin ? { input : Buffer . from ( opts . stdin || "" ) } : { } ) ,
1163
1153
} ) . exec ( ) ;
1164
- if ( exitCode !== 0 )
1154
+ if ( exitCode !== 0 ) {
1155
+ error = extractFatalErrors ( error ) || error ;
1165
1156
throw new CommandInvocationError ( cmd , args , exitCode , error , output ) ;
1157
+ }
1166
1158
return output ;
1167
1159
}
1168
1160
1161
+ function extractFatalErrors ( error : string ) : string | undefined {
1162
+ const fatalErrors : string [ ] = [ ] ;
1163
+ const fatalErrorRegex = / .* f a t a l e r r o r o c c u r r e d : / gi;
1164
+ let lastFatalErrorIndex : number | undefined ;
1165
+ let match : RegExpMatchArray | null ;
1166
+ while ( ( match = fatalErrorRegex . exec ( error ) ) !== null ) {
1167
+ if ( lastFatalErrorIndex !== undefined ) {
1168
+ fatalErrors . push ( error . slice ( lastFatalErrorIndex , match . index ) ) ;
1169
+ }
1170
+ lastFatalErrorIndex = match . index ;
1171
+ }
1172
+ if ( lastFatalErrorIndex !== undefined ) {
1173
+ const lastError = error . slice ( lastFatalErrorIndex ) ;
1174
+ return (
1175
+ lastError +
1176
+ ( fatalErrors . length > 0 ? `\nContext:\n${ fatalErrors . join ( "\n" ) } ` : "" )
1177
+ ) ;
1178
+ }
1179
+ return undefined ;
1180
+ }
1181
+
1169
1182
/**
1170
1183
* If appropriate, generates a code scanning configuration that is to be used for a scan.
1171
1184
* If the configuration is not to be generated, returns undefined.
0 commit comments