Display the error message on one line if possible

This commit is contained in:
Henry Mercer 2023-07-21 11:40:07 +01:00
parent 0f871fa80d
commit 65a297b952
6 changed files with 14 additions and 10 deletions

6
lib/codeql.js generated
View file

@ -41,8 +41,10 @@ class CommandInvocationError extends Error {
const prettyCommand = [cmd, ...args] const prettyCommand = [cmd, ...args]
.map((x) => (x.includes(" ") ? `'${x}'` : x)) .map((x) => (x.includes(" ") ? `'${x}'` : x))
.join(" "); .join(" ");
super(`Encountered a fatal error while running "${prettyCommand}".\n` + error = error.trim();
`Exit code was ${exitCode} and error was:\n` + const separator = error.includes("\n") ? "\n" : " ";
super(`Encountered a fatal error while running "${prettyCommand}".${separator}` +
`Exit code was ${exitCode} and error was:${separator}` +
`${error}`); `${error}`);
this.exitCode = exitCode; this.exitCode = exitCode;
this.error = error; this.error = error;

File diff suppressed because one or more lines are too long

4
lib/codeql.test.js generated
View file

@ -738,8 +738,8 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
// safeWhich throws because of the test CodeQL object. // safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves(""); sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"), { await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"), {
message: 'Encountered a fatal error while running "codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db".\n' + message: 'Encountered a fatal error while running "codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db". ' +
`Exit code was 32 and error was:\n${cliMessage}`, `Exit code was 32 and error was: ${cliMessage}`,
}); });
}); });
function stubToolRunnerConstructor(exitCode = 0, stderr) { function stubToolRunnerConstructor(exitCode = 0, stderr) {

File diff suppressed because one or more lines are too long

View file

@ -1189,8 +1189,8 @@ test("database finalize does not override no code found error on CodeQL 2.12.4",
await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"), await codeqlObject.finalizeDatabase("db", "--threads=2", "--ram=2048"),
{ {
message: message:
'Encountered a fatal error while running "codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db".\n' + 'Encountered a fatal error while running "codeql-for-testing database finalize --finalize-dataset --threads=2 --ram=2048 db". ' +
`Exit code was 32 and error was:\n${cliMessage}`, `Exit code was 32 and error was: ${cliMessage}`,
} }
); );
}); });

View file

@ -54,9 +54,11 @@ export class CommandInvocationError extends Error {
const prettyCommand = [cmd, ...args] const prettyCommand = [cmd, ...args]
.map((x) => (x.includes(" ") ? `'${x}'` : x)) .map((x) => (x.includes(" ") ? `'${x}'` : x))
.join(" "); .join(" ");
error = error.trim();
const separator = error.includes("\n") ? "\n" : " ";
super( super(
`Encountered a fatal error while running "${prettyCommand}".\n` + `Encountered a fatal error while running "${prettyCommand}".${separator}` +
`Exit code was ${exitCode} and error was:\n` + `Exit code was ${exitCode} and error was:${separator}` +
`${error}` `${error}`
); );
} }