Improve formatting of fatal errors

This commit is contained in:
Henry Mercer
2023-07-21 14:39:30 +01:00
parent 2eb34f2fb9
commit fdedc91de2
3 changed files with 28 additions and 7 deletions

16
lib/codeql.js generated
View File

@@ -742,8 +742,8 @@ async function runTool(cmd, args = [], opts = {}) {
return output;
}
function extractFatalErrors(error) {
const fatalErrors = [];
const fatalErrorRegex = /.*fatal error occurred:/gi;
let fatalErrors = [];
let lastFatalErrorIndex;
let match;
while ((match = fatalErrorRegex.exec(error)) !== null) {
@@ -758,11 +758,21 @@ function extractFatalErrors(error) {
// No other errors
return lastError;
}
const separator = fatalErrors.some((e) => e.includes("\n")) ? "\n" : " ";
return [lastError, "Context:", ...fatalErrors.reverse()].join(separator);
const isOneLiner = !fatalErrors.some((e) => e.includes("\n"));
if (isOneLiner) {
fatalErrors = fatalErrors.map(ensureEndsInPeriod);
}
return [
ensureEndsInPeriod(lastError),
"Context:",
...fatalErrors.reverse(),
].join(isOneLiner ? " " : "\n");
}
return undefined;
}
function ensureEndsInPeriod(text) {
return text[text.length - 1] === "." ? text : `${text}.`;
}
/**
* If appropriate, generates a code scanning configuration that is to be used for a scan.
* If the configuration is not to be generated, returns undefined.