mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 14:40:10 +08:00
Merge branch 'main' into henrymercer/simplify-actions-only
This commit is contained in:
@@ -357,33 +357,19 @@ async function run() {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
||||
if (error instanceof CodeQLAnalysisError) {
|
||||
const stats = { ...error.queriesStatusReport };
|
||||
await sendStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
stats,
|
||||
error,
|
||||
trapCacheUploadTime,
|
||||
dbCreationTimings,
|
||||
didUploadTrapCaches,
|
||||
trapCacheCleanupTelemetry,
|
||||
logger,
|
||||
);
|
||||
} else {
|
||||
await sendStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
undefined,
|
||||
error,
|
||||
trapCacheUploadTime,
|
||||
dbCreationTimings,
|
||||
didUploadTrapCaches,
|
||||
trapCacheCleanupTelemetry,
|
||||
logger,
|
||||
);
|
||||
}
|
||||
|
||||
await sendStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
error instanceof CodeQLAnalysisError
|
||||
? error.queriesStatusReport
|
||||
: undefined,
|
||||
error instanceof CodeQLAnalysisError ? error.error : error,
|
||||
trapCacheUploadTime,
|
||||
dbCreationTimings,
|
||||
didUploadTrapCaches,
|
||||
trapCacheCleanupTelemetry,
|
||||
logger,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ import * as util from "./util";
|
||||
import { BuildMode } from "./util";
|
||||
|
||||
export class CodeQLAnalysisError extends Error {
|
||||
queriesStatusReport: QueriesStatusReport;
|
||||
|
||||
constructor(queriesStatusReport: QueriesStatusReport, message: string) {
|
||||
constructor(
|
||||
public queriesStatusReport: QueriesStatusReport,
|
||||
public message: string,
|
||||
public error: Error,
|
||||
) {
|
||||
super(message);
|
||||
|
||||
this.name = "CodeQLAnalysisError";
|
||||
this.queriesStatusReport = queriesStatusReport;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +315,7 @@ export async function runQueries(
|
||||
throw new CodeQLAnalysisError(
|
||||
statusReport,
|
||||
`Error running analysis for ${language}: ${util.wrapError(e).message}`,
|
||||
util.wrapError(e),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ export class CommandInvocationError extends Error {
|
||||
if (fatalErrors) {
|
||||
message =
|
||||
`Encountered a fatal error while running "${prettyCommand}". ` +
|
||||
`Exit code was ${exitCode} and error was: ${fatalErrors.trim()} See the logs for more details.`;
|
||||
`Exit code was ${exitCode} and error was: ${ensureEndsInPeriod(
|
||||
fatalErrors.trim(),
|
||||
)} See the logs for more details.`;
|
||||
} else if (autobuildErrors) {
|
||||
const autobuildHelpLink =
|
||||
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed";
|
||||
@@ -32,10 +34,9 @@ export class CommandInvocationError extends Error {
|
||||
`For more information, see ${autobuildHelpLink}. ` +
|
||||
`Encountered the following error: ${autobuildErrors}`;
|
||||
} else {
|
||||
let lastLine = stderr.trim().split("\n").pop()?.trim() || "";
|
||||
if (lastLine[lastLine.length - 1] !== ".") {
|
||||
lastLine += ".";
|
||||
}
|
||||
const lastLine = ensureEndsInPeriod(
|
||||
stderr.trim().split("\n").pop()?.trim() || "n/a",
|
||||
);
|
||||
message =
|
||||
`Encountered a fatal error while running "${prettyCommand}". ` +
|
||||
`Exit code was ${exitCode} and last log line was: ${lastLine} See the logs for more details.`;
|
||||
@@ -75,7 +76,7 @@ export class CommandInvocationError extends Error {
|
||||
* the Actions UI.
|
||||
*/
|
||||
function extractFatalErrors(error: string): string | undefined {
|
||||
const fatalErrorRegex = /.*fatal error occurred:/gi;
|
||||
const fatalErrorRegex = /.*fatal (internal )?error occurr?ed(. Details)?:/gi;
|
||||
let fatalErrors: string[] = [];
|
||||
let lastFatalErrorIndex: number | undefined;
|
||||
let match: RegExpMatchArray | null;
|
||||
|
||||
@@ -950,6 +950,31 @@ test("runTool truncates long autobuilder errors", async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test("runTool recognizes fatal internal errors", async (t) => {
|
||||
const stderr = `
|
||||
[11/31 eval 8m19s] Evaluation done; writing results to codeql/go-queries/Security/CWE-020/MissingRegexpAnchor.bqrs.
|
||||
Oops! A fatal internal error occurred. Details:
|
||||
com.semmle.util.exception.CatastrophicError: An error occurred while evaluating ControlFlowGraph::ControlFlow::Root.isRootOf/1#dispred#f610e6ed/2@86282cc8
|
||||
Severe disk cache trouble (corruption or out of space) at /home/runner/work/_temp/codeql_databases/go/db-go/default/cache/pages/28/33.pack: Failed to write item to disk`;
|
||||
stubToolRunnerConstructor(1, stderr);
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.6"));
|
||||
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
await t.throwsAsync(
|
||||
async () =>
|
||||
await codeqlObject.databaseRunQueries(stubConfig.dbLocation, []),
|
||||
{
|
||||
instanceOf: CommandInvocationError,
|
||||
message: `Encountered a fatal error while running "codeql-for-testing database run-queries --expect-discarded-cache --min-disk-free=1024 -v". Exit code was 1 and error was: Oops! A fatal internal error occurred. Details:
|
||||
com.semmle.util.exception.CatastrophicError: An error occurred while evaluating ControlFlowGraph::ControlFlow::Root.isRootOf/1#dispred#f610e6ed/2@86282cc8
|
||||
Severe disk cache trouble (corruption or out of space) at /home/runner/work/_temp/codeql_databases/go/db-go/default/cache/pages/28/33.pack: Failed to write item to disk. See the logs for more details.`,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("runTool outputs last line of stderr if fatal error could not be found", async (t) => {
|
||||
const cliStderr = "line1\nline2\nline3\nline4\nline5";
|
||||
stubToolRunnerConstructor(32, cliStderr);
|
||||
|
||||
Reference in New Issue
Block a user