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

File diff suppressed because one or more lines are too long

View File

@@ -1161,8 +1161,8 @@ async function runTool(
} }
function extractFatalErrors(error: string): string | undefined { function extractFatalErrors(error: string): string | undefined {
const fatalErrors: string[] = [];
const fatalErrorRegex = /.*fatal error occurred:/gi; const fatalErrorRegex = /.*fatal error occurred:/gi;
let fatalErrors: string[] = [];
let lastFatalErrorIndex: number | undefined; let lastFatalErrorIndex: number | undefined;
let match: RegExpMatchArray | null; let match: RegExpMatchArray | null;
while ((match = fatalErrorRegex.exec(error)) !== null) { while ((match = fatalErrorRegex.exec(error)) !== null) {
@@ -1177,12 +1177,23 @@ function extractFatalErrors(error: string): string | undefined {
// No other errors // No other errors
return lastError; return lastError;
} }
const separator = fatalErrors.some((e) => e.includes("\n")) ? "\n" : " "; const isOneLiner = !fatalErrors.some((e) => e.includes("\n"));
return [lastError, "Context:", ...fatalErrors.reverse()].join(separator); if (isOneLiner) {
fatalErrors = fatalErrors.map(ensureEndsInPeriod);
}
return [
ensureEndsInPeriod(lastError),
"Context:",
...fatalErrors.reverse(),
].join(isOneLiner ? " " : "\n");
} }
return undefined; return undefined;
} }
function ensureEndsInPeriod(text: string): string {
return text[text.length - 1] === "." ? text : `${text}.`;
}
/** /**
* If appropriate, generates a code scanning configuration that is to be used for a scan. * 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. * If the configuration is not to be generated, returns undefined.