Mark third-party SARIF limits errors as configuration errors
This commit is contained in:
parent
bd56a05133
commit
888ab31e3e
12 changed files with 63 additions and 62 deletions
36
lib/upload-lib.js
generated
36
lib/upload-lib.js
generated
|
|
@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.validateUniqueCategory = exports.waitForProcessing = exports.buildPayload = exports.validateSarifFileSchema = exports.uploadFromActions = exports.findSarifFilesInDir = exports.populateRunAutomationDetails = void 0;
|
||||
exports.InvalidSarifUploadError = exports.validateUniqueCategory = exports.waitForProcessing = exports.buildPayload = exports.validateSarifFileSchema = exports.uploadFromActions = exports.findSarifFilesInDir = exports.populateRunAutomationDetails = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const zlib_1 = __importDefault(require("zlib"));
|
||||
|
|
@ -151,22 +151,9 @@ exports.findSarifFilesInDir = findSarifFilesInDir;
|
|||
/**
|
||||
* Uploads a single SARIF file or a directory of SARIF files depending on what `sarifPath` refers
|
||||
* to.
|
||||
*
|
||||
* @param isThirdPartyUpload Whether the SARIF to upload comes from a third party, or from
|
||||
* first-party CodeQL analysis. If it comes from a third party,
|
||||
* we classify certain errors as configuration errors for
|
||||
* telemetry purposes.
|
||||
*/
|
||||
async function uploadFromActions(sarifPath, checkoutPath, category, logger, { isThirdPartyUpload: isThirdPartyUpload }) {
|
||||
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 InvalidSarifUploadError && isThirdPartyUpload) {
|
||||
throw new util_1.ConfigurationError(e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
async function uploadFromActions(sarifPath, checkoutPath, category, logger) {
|
||||
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);
|
||||
}
|
||||
exports.uploadFromActions = uploadFromActions;
|
||||
function getSarifFilePaths(sarifPath) {
|
||||
|
|
@ -364,9 +351,12 @@ 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 shouldConsiderConfigurationError(response.data.errors)
|
||||
const processingErrors = response.data.errors;
|
||||
throw shouldConsiderConfigurationError(processingErrors)
|
||||
? new util_1.ConfigurationError(message)
|
||||
: new InvalidSarifUploadError(message);
|
||||
: shouldConsiderInvalidRequest(processingErrors)
|
||||
? new InvalidSarifUploadError(message)
|
||||
: new Error(message);
|
||||
}
|
||||
else {
|
||||
util.assertNever(status);
|
||||
|
|
@ -382,13 +372,20 @@ async function waitForProcessing(repositoryNwo, sarifID, logger, options = {
|
|||
}
|
||||
exports.waitForProcessing = waitForProcessing;
|
||||
/**
|
||||
* Returns whether the provided processing errors should be considered a user error.
|
||||
* Returns whether the provided processing errors are a configuration error.
|
||||
*/
|
||||
function shouldConsiderConfigurationError(processingErrors) {
|
||||
return (processingErrors.length === 1 &&
|
||||
processingErrors[0] ===
|
||||
"CodeQL analyses from advanced configurations cannot be processed when the default setup is enabled");
|
||||
}
|
||||
/**
|
||||
* Returns whether the provided processing errors are the result of an invalid SARIF upload request.
|
||||
*/
|
||||
function shouldConsiderInvalidRequest(processingErrors) {
|
||||
return (processingErrors.length === 1 &&
|
||||
processingErrors[0].startsWith("rejecting SARIF,"));
|
||||
}
|
||||
/**
|
||||
* Checks the processing result for an unsuccessful execution. Throws if the
|
||||
* result is not a failure with a single "unsuccessful execution" error.
|
||||
|
|
@ -458,4 +455,5 @@ class InvalidSarifUploadError extends Error {
|
|||
super(message);
|
||||
}
|
||||
}
|
||||
exports.InvalidSarifUploadError = InvalidSarifUploadError;
|
||||
//# sourceMappingURL=upload-lib.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue