Refactor configuration errors (#2105)

Refactor the existing classes of configuration errors into their own file; consolidate the place we check for configuration errors into `codeql.ts`, where the actual command invocations happen.

Also, rename the `UserError` type to `ConfigurationError` to standardize on a single term.
This commit is contained in:
Angela P Wen
2024-02-08 09:20:03 -08:00
committed by GitHub
parent fc9f9e5ef9
commit 1515e2bb20
54 changed files with 654 additions and 502 deletions

14
lib/upload-lib.js generated
View File

@@ -132,17 +132,17 @@ exports.findSarifFilesInDir = findSarifFilesInDir;
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
* to.
*
* @param considerInvalidRequestUserError Whether an invalid request, for example one with a
* @param considerInvalidRequestConfigError Whether an invalid request, for example one with a
* `sarifPath` that does not exist, should be considered a
* user error.
*/
async function uploadFromActions(sarifPath, checkoutPath, category, logger, { considerInvalidRequestUserError, }) {
async function uploadFromActions(sarifPath, checkoutPath, category, logger, { considerInvalidRequestConfigError: considerInvalidRequestConfigError, }) {
try {
return await uploadFiles(getSarifFilePaths(sarifPath), (0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY")), await actionsUtil.getCommitOid(checkoutPath), await actionsUtil.getRef(), await api.getAnalysisKey(), category, util.getRequiredEnvParam("GITHUB_WORKFLOW"), actionsUtil.getWorkflowRunID(), actionsUtil.getWorkflowRunAttempt(), checkoutPath, actionsUtil.getRequiredInput("matrix"), logger);
}
catch (e) {
if (e instanceof InvalidRequestError && considerInvalidRequestUserError) {
throw new util_1.UserError(e.message);
if (e instanceof InvalidRequestError && considerInvalidRequestConfigError) {
throw new util_1.ConfigurationError(e.message);
}
throw e;
}
@@ -343,8 +343,8 @@ async function waitForProcessing(repositoryNwo, sarifID, logger, options = {
}
else if (status === "failed") {
const message = `Code Scanning could not process the submitted SARIF file:\n${response.data.errors}`;
throw shouldConsiderAsUserError(response.data.errors)
? new util_1.UserError(message)
throw shouldConsiderConfigurationError(response.data.errors)
? new util_1.ConfigurationError(message)
: new InvalidRequestError(message);
}
else {
@@ -363,7 +363,7 @@ exports.waitForProcessing = waitForProcessing;
/**
* Returns whether the provided processing errors should be considered a user error.
*/
function shouldConsiderAsUserError(processingErrors) {
function shouldConsiderConfigurationError(processingErrors) {
return (processingErrors.length === 1 &&
processingErrors[0] ===
"CodeQL analyses from advanced configurations cannot be processed when the default setup is enabled");