Surface fatal CLI errors in interpret-results and run-queries (#1407)

Co-authored-by: Henry Mercer <henry.mercer@me.com>
This commit is contained in:
Angela P Wen 2022-12-02 14:05:21 +01:00 committed by GitHub
parent 0d9b15ca93
commit aa0e650c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 137 additions and 85 deletions

View file

@ -1016,7 +1016,7 @@ async function getCodeQLForCmd(
if (querySuitePath) {
codeqlArgs.push(querySuitePath);
}
await runTool(cmd, codeqlArgs);
await toolrunnerErrorCatcher(cmd, codeqlArgs, errorMatchers);
},
async databaseInterpretResults(
databasePath: string,
@ -1059,7 +1059,12 @@ async function getCodeQLForCmd(
codeqlArgs.push(...querySuitePaths);
}
// capture stdout, which contains analysis summaries
return await runTool(cmd, codeqlArgs);
const returnState = await toolrunnerErrorCatcher(
cmd,
codeqlArgs,
errorMatchers
);
return returnState.stdout;
},
async databasePrintBaseline(databasePath: string): Promise<string> {
const codeqlArgs = [
@ -1247,11 +1252,16 @@ async function runTool(cmd: string, args: string[] = []) {
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
output += data.toString("utf8");
},
stderr: (data: Buffer) => {
const toRead = Math.min(maxErrorSize - error.length, data.length);
error += data.toString("utf8", 0, toRead);
let readStartIndex = 0;
// If the error is too large, then we only take the last 20,000 characters
if (data.length - maxErrorSize > 0) {
// Eg: if we have 20,000 the start index should be 2.
readStartIndex = data.length - maxErrorSize + 1;
}
error += data.toString("utf8", readStartIndex);
},
},
ignoreReturnCode: true,