Improve error messages from CLI invocations

This commit is contained in:
Edoardo Pirovano 2021-06-24 17:30:42 +01:00 committed by Edoardo Pirovano
parent db80a9a7c3
commit 40852fa52a
3 changed files with 62 additions and 3 deletions

30
lib/codeql.js generated
View file

@ -23,6 +23,14 @@ const error_matcher_1 = require("./error-matcher");
const toolcache = __importStar(require("./toolcache"));
const toolrunner_error_catcher_1 = require("./toolrunner-error-catcher");
const util = __importStar(require("./util"));
class CommandInvocationError extends Error {
constructor(cmd, args, exitCode, error) {
super(`Failure invoking ${cmd} with arguments ${args}.\n
Exit code ${exitCode} and error was:\n
${error}`);
}
}
exports.CommandInvocationError = CommandInvocationError;
/**
* Stores the CodeQL object, and is populated by `setupCodeQL` or `getCodeQL`.
* Can be overridden in tests using `setCodeQL`.
@ -577,15 +585,35 @@ function getExtraOptions(options, paths, pathInfo) {
return all.concat(specific);
}
exports.getExtraOptions = getExtraOptions;
/*
* A constant defining the maximum number of characters we will keep from
* the programs stderr for logging. This serves two purposes:
* (1) It avoids an OOM if a program fails in a way that results it
* printing many log lines.
* (2) It avoids us hitting the limit of how much data we can send in our
* status reports on GitHub.com.
* This value was chosen because the maximum size of fields in the status
* report is 100kb and UTF8 characters can be up to four bytes. 5,000
* characters are left over to include other information.
*/
const maxErrorSize = 20000;
async function runTool(cmd, args = []) {
let output = "";
await new toolrunner.ToolRunner(cmd, args, {
let error = "";
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
listeners: {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
const toRead = Math.min(maxErrorSize - error.length, data.length);
error += data.toString("utf8", 0, toRead);
},
},
ignoreReturnCode: true,
}).exec();
if (exitCode !== 0)
throw new CommandInvocationError(cmd, args, exitCode, error);
return output;
}
//# sourceMappingURL=codeql.js.map