Skip to content

Commit 21c9267

Browse files
committed
Capture the details of fatal errors
1 parent 76b2afa commit 21c9267

File tree

7 files changed

+63
-371
lines changed

7 files changed

+63
-371
lines changed

lib/codeql.js

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { getOptionalInput, isAnalyzingDefaultBranch } from "./actions-util";
99
import * as api from "./api-client";
1010
import type { Config } from "./config-utils";
1111
import { EnvVar } from "./environment";
12-
import { errorMatchers } from "./error-matcher";
1312
import {
1413
CODEQL_VERSION_NEW_ANALYSIS_SUMMARY,
1514
CodeQLDefaultVersionInfo,
@@ -20,7 +19,6 @@ import {
2019
import { isTracedLanguage, Language } from "./languages";
2120
import { Logger } from "./logging";
2221
import * as setupCodeql from "./setup-codeql";
23-
import { toolrunnerErrorCatcher } from "./toolrunner-error-catcher";
2422
import * as util from "./util";
2523
import { wrapError } from "./util";
2624

@@ -627,19 +625,15 @@ export async function getCodeQLForCmd(
627625
`autobuild${ext}`
628626
);
629627
// 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+
]);
643637
},
644638
async finalizeDatabase(
645639
databasePath: string,
@@ -782,7 +776,7 @@ export async function getCodeQLForCmd(
782776
if (querySuitePath) {
783777
codeqlArgs.push(querySuitePath);
784778
}
785-
await toolrunnerErrorCatcher(cmd, codeqlArgs, errorMatchers);
779+
await runTool(cmd, codeqlArgs);
786780
},
787781
async databaseInterpretResults(
788782
databasePath: string,
@@ -848,17 +842,13 @@ export async function getCodeQLForCmd(
848842
codeqlArgs.push(...querySuitePaths);
849843
}
850844
// 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);
856846

857847
if (shouldWorkaroundInvalidNotifications) {
858848
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
859849
}
860850

861-
return returnState.stdout;
851+
return returnState;
862852
},
863853
async databasePrintBaseline(databasePath: string): Promise<string> {
864854
const codeqlArgs = [
@@ -1161,11 +1151,34 @@ async function runTool(
11611151
ignoreReturnCode: true,
11621152
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
11631153
}).exec();
1164-
if (exitCode !== 0)
1154+
if (exitCode !== 0) {
1155+
error = extractFatalErrors(error) || error;
11651156
throw new CommandInvocationError(cmd, args, exitCode, error, output);
1157+
}
11661158
return output;
11671159
}
11681160

1161+
function extractFatalErrors(error: string): string | undefined {
1162+
const fatalErrors: string[] = [];
1163+
const fatalErrorRegex = /.*fatal error occurred:/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+
11691182
/**
11701183
* If appropriate, generates a code scanning configuration that is to be used for a scan.
11711184
* If the configuration is not to be generated, returns undefined.

src/error-matcher.test.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/error-matcher.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)