Improve CommandInvocationError message

This commit is contained in:
Henry Mercer 2023-07-20 18:58:37 +01:00
parent c84418936e
commit 0f871fa80d
6 changed files with 19 additions and 12 deletions

7
lib/codeql.js generated
View file

@ -38,8 +38,11 @@ const util = __importStar(require("./util"));
const util_1 = require("./util");
class CommandInvocationError extends Error {
constructor(cmd, args, exitCode, error, output) {
super(`Failure invoking ${cmd} with arguments ${args}.\n` +
`Exit code ${exitCode} and error was:\n` +
const prettyCommand = [cmd, ...args]
.map((x) => (x.includes(" ") ? `'${x}'` : x))
.join(" ");
super(`Encountered a fatal error while running "${prettyCommand}".\n` +
`Exit code was ${exitCode} and error was:\n` +
`${error}`);
this.exitCode = exitCode;
this.error = error;

File diff suppressed because one or more lines are too long

6
lib/codeql.test.js generated
View file

@ -737,9 +737,9 @@ for (const { featureEnabled, codeqlVersion, flagPassed, negativeFlagPassed, } of
sinon.stub(codeqlObject, "getVersion").resolves("2.12.4");
// safeWhich throws because of the test CodeQL object.
sinon.stub(safeWhich, "safeWhich").resolves("");
await t.throwsAsync(async () => await codeqlObject.finalizeDatabase("", "", ""), {
message: "Failure invoking codeql-for-testing with arguments database,finalize,--finalize-dataset,,,.\n" +
`Exit code 32 and error was:\n${cliMessage}`,
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' +
`Exit code was 32 and error was:\n${cliMessage}`,
});
});
function stubToolRunnerConstructor(exitCode = 0, stderr) {

File diff suppressed because one or more lines are too long