Wrap configuration errors for all CLI commands
This commit is contained in:
parent
294b6df61d
commit
7f375aeb76
3 changed files with 43 additions and 86 deletions
61
lib/codeql.js
generated
61
lib/codeql.js
generated
|
|
@ -297,24 +297,16 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
else if (await util.codeQlVersionAbove(this, exports.CODEQL_VERSION_SUBLANGUAGE_FILE_COVERAGE)) {
|
else if (await util.codeQlVersionAbove(this, exports.CODEQL_VERSION_SUBLANGUAGE_FILE_COVERAGE)) {
|
||||||
extraArgs.push("--no-sublanguage-file-coverage");
|
extraArgs.push("--no-sublanguage-file-coverage");
|
||||||
}
|
}
|
||||||
try {
|
await runTool(cmd, [
|
||||||
await runTool(cmd, [
|
"database",
|
||||||
"database",
|
"init",
|
||||||
"init",
|
"--db-cluster",
|
||||||
"--db-cluster",
|
config.dbLocation,
|
||||||
config.dbLocation,
|
`--source-root=${sourceRoot}`,
|
||||||
`--source-root=${sourceRoot}`,
|
...(await getLanguageAliasingArguments(this)),
|
||||||
...(await getLanguageAliasingArguments(this)),
|
...extraArgs,
|
||||||
...extraArgs,
|
...getExtraOptionsFromEnv(["database", "init"]),
|
||||||
...getExtraOptionsFromEnv(["database", "init"]),
|
], { stdin: externalRepositoryToken });
|
||||||
], { stdin: externalRepositoryToken });
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw (0, cli_errors_1.wrapCliConfigurationError)(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async runAutobuild(language, enableDebugLogging) {
|
async runAutobuild(language, enableDebugLogging) {
|
||||||
const autobuildCmd = path.join(await this.resolveExtractor(language), "tools", process.platform === "win32" ? "autobuild.cmd" : "autobuild.sh");
|
const autobuildCmd = path.join(await this.resolveExtractor(language), "tools", process.platform === "win32" ? "autobuild.cmd" : "autobuild.sh");
|
||||||
|
|
@ -347,15 +339,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
// When `DYLD_INSERT_LIBRARIES` is set in the environment for a step,
|
// When `DYLD_INSERT_LIBRARIES` is set in the environment for a step,
|
||||||
// the Actions runtime introduces its own workaround for SIP
|
// the Actions runtime introduces its own workaround for SIP
|
||||||
// (https://github.com/actions/runner/pull/416).
|
// (https://github.com/actions/runner/pull/416).
|
||||||
try {
|
await runTool(autobuildCmd);
|
||||||
await runTool(autobuildCmd);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw (0, cli_errors_1.wrapCliConfigurationError)(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async extractScannedLanguage(config, language) {
|
async extractScannedLanguage(config, language) {
|
||||||
await runTool(cmd, [
|
await runTool(cmd, [
|
||||||
|
|
@ -390,15 +374,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
...getExtraOptionsFromEnv(["database", "finalize"]),
|
...getExtraOptionsFromEnv(["database", "finalize"]),
|
||||||
databasePath,
|
databasePath,
|
||||||
];
|
];
|
||||||
try {
|
await runTool(cmd, args);
|
||||||
await runTool(cmd, args);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw (0, cli_errors_1.wrapCliConfigurationError)(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async resolveLanguages() {
|
async resolveLanguages() {
|
||||||
const codeqlArgs = [
|
const codeqlArgs = [
|
||||||
|
|
@ -776,14 +752,14 @@ exports.getExtraOptions = getExtraOptions;
|
||||||
*/
|
*/
|
||||||
const maxErrorSize = 20_000;
|
const maxErrorSize = 20_000;
|
||||||
async function runTool(cmd, args = [], opts = {}) {
|
async function runTool(cmd, args = [], opts = {}) {
|
||||||
let output = "";
|
let stdout = "";
|
||||||
let error = "";
|
let stderr = "";
|
||||||
process.stdout.write(`[command]${cmd} ${args.join(" ")}\n`);
|
process.stdout.write(`[command]${cmd} ${args.join(" ")}\n`);
|
||||||
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
|
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
output += data.toString("utf8");
|
stdout += data.toString("utf8");
|
||||||
if (!opts.noStreamStdout) {
|
if (!opts.noStreamStdout) {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
|
|
@ -795,7 +771,7 @@ async function runTool(cmd, args = [], opts = {}) {
|
||||||
// Eg: if we have 20,000 the start index should be 2.
|
// Eg: if we have 20,000 the start index should be 2.
|
||||||
readStartIndex = data.length - maxErrorSize + 1;
|
readStartIndex = data.length - maxErrorSize + 1;
|
||||||
}
|
}
|
||||||
error += data.toString("utf8", readStartIndex);
|
stderr += data.toString("utf8", readStartIndex);
|
||||||
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
|
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
},
|
},
|
||||||
|
|
@ -804,9 +780,10 @@ async function runTool(cmd, args = [], opts = {}) {
|
||||||
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
|
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
|
||||||
}).exec();
|
}).exec();
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
throw new cli_errors_1.CommandInvocationError(cmd, args, exitCode, error, output);
|
const e = new cli_errors_1.CommandInvocationError(cmd, args, exitCode, stderr, stdout);
|
||||||
|
throw (0, cli_errors_1.wrapCliConfigurationError)(e);
|
||||||
}
|
}
|
||||||
return output;
|
return stdout;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generates a code scanning configuration that is to be used for a scan.
|
* Generates a code scanning configuration that is to be used for a scan.
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -616,27 +616,20 @@ export async function getCodeQLForCmd(
|
||||||
extraArgs.push("--no-sublanguage-file-coverage");
|
extraArgs.push("--no-sublanguage-file-coverage");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await runTool(
|
||||||
await runTool(
|
cmd,
|
||||||
cmd,
|
[
|
||||||
[
|
"database",
|
||||||
"database",
|
"init",
|
||||||
"init",
|
"--db-cluster",
|
||||||
"--db-cluster",
|
config.dbLocation,
|
||||||
config.dbLocation,
|
`--source-root=${sourceRoot}`,
|
||||||
`--source-root=${sourceRoot}`,
|
...(await getLanguageAliasingArguments(this)),
|
||||||
...(await getLanguageAliasingArguments(this)),
|
...extraArgs,
|
||||||
...extraArgs,
|
...getExtraOptionsFromEnv(["database", "init"]),
|
||||||
...getExtraOptionsFromEnv(["database", "init"]),
|
],
|
||||||
],
|
{ stdin: externalRepositoryToken },
|
||||||
{ stdin: externalRepositoryToken },
|
);
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw wrapCliConfigurationError(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async runAutobuild(language: Language, enableDebugLogging: boolean) {
|
async runAutobuild(language: Language, enableDebugLogging: boolean) {
|
||||||
const autobuildCmd = path.join(
|
const autobuildCmd = path.join(
|
||||||
|
|
@ -677,14 +670,7 @@ export async function getCodeQLForCmd(
|
||||||
// When `DYLD_INSERT_LIBRARIES` is set in the environment for a step,
|
// When `DYLD_INSERT_LIBRARIES` is set in the environment for a step,
|
||||||
// the Actions runtime introduces its own workaround for SIP
|
// the Actions runtime introduces its own workaround for SIP
|
||||||
// (https://github.com/actions/runner/pull/416).
|
// (https://github.com/actions/runner/pull/416).
|
||||||
try {
|
await runTool(autobuildCmd);
|
||||||
await runTool(autobuildCmd);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw wrapCliConfigurationError(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async extractScannedLanguage(config: Config, language: Language) {
|
async extractScannedLanguage(config: Config, language: Language) {
|
||||||
await runTool(cmd, [
|
await runTool(cmd, [
|
||||||
|
|
@ -724,14 +710,7 @@ export async function getCodeQLForCmd(
|
||||||
...getExtraOptionsFromEnv(["database", "finalize"]),
|
...getExtraOptionsFromEnv(["database", "finalize"]),
|
||||||
databasePath,
|
databasePath,
|
||||||
];
|
];
|
||||||
try {
|
await runTool(cmd, args);
|
||||||
await runTool(cmd, args);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
throw wrapCliConfigurationError(e);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async resolveLanguages() {
|
async resolveLanguages() {
|
||||||
const codeqlArgs = [
|
const codeqlArgs = [
|
||||||
|
|
@ -1215,14 +1194,14 @@ async function runTool(
|
||||||
args: string[] = [],
|
args: string[] = [],
|
||||||
opts: { stdin?: string; noStreamStdout?: boolean } = {},
|
opts: { stdin?: string; noStreamStdout?: boolean } = {},
|
||||||
) {
|
) {
|
||||||
let output = "";
|
let stdout = "";
|
||||||
let error = "";
|
let stderr = "";
|
||||||
process.stdout.write(`[command]${cmd} ${args.join(" ")}\n`);
|
process.stdout.write(`[command]${cmd} ${args.join(" ")}\n`);
|
||||||
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
|
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
output += data.toString("utf8");
|
stdout += data.toString("utf8");
|
||||||
if (!opts.noStreamStdout) {
|
if (!opts.noStreamStdout) {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
|
|
@ -1234,7 +1213,7 @@ async function runTool(
|
||||||
// Eg: if we have 20,000 the start index should be 2.
|
// Eg: if we have 20,000 the start index should be 2.
|
||||||
readStartIndex = data.length - maxErrorSize + 1;
|
readStartIndex = data.length - maxErrorSize + 1;
|
||||||
}
|
}
|
||||||
error += data.toString("utf8", readStartIndex);
|
stderr += data.toString("utf8", readStartIndex);
|
||||||
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
|
// Mimic the standard behavior of the toolrunner by writing stderr to stdout
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
},
|
},
|
||||||
|
|
@ -1243,9 +1222,10 @@ async function runTool(
|
||||||
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
|
...(opts.stdin ? { input: Buffer.from(opts.stdin || "") } : {}),
|
||||||
}).exec();
|
}).exec();
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
throw new CommandInvocationError(cmd, args, exitCode, error, output);
|
const e = new CommandInvocationError(cmd, args, exitCode, stderr, stdout);
|
||||||
|
throw wrapCliConfigurationError(e);
|
||||||
}
|
}
|
||||||
return output;
|
return stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue