Mark some upload-sarif errors as always configuration errors

This commit is contained in:
Henry Mercer 2024-04-15 15:52:19 +01:00
parent a22989dcd4
commit e006461bad
3 changed files with 13 additions and 7 deletions

9
lib/upload-lib.js generated
View file

@ -226,13 +226,15 @@ async function uploadFromActions(sarifPath, checkoutPath, category, logger) {
exports.uploadFromActions = uploadFromActions;
function getSarifFilePaths(sarifPath) {
if (!fs.existsSync(sarifPath)) {
throw new InvalidSarifUploadError(`Path does not exist: ${sarifPath}`);
// This is always a configuration error, even for first-party runs.
throw new util_1.ConfigurationError(`Path does not exist: ${sarifPath}`);
}
let sarifFiles;
if (fs.lstatSync(sarifPath).isDirectory()) {
sarifFiles = findSarifFilesInDir(sarifPath);
if (sarifFiles.length === 0) {
throw new InvalidSarifUploadError(`No SARIF files found to upload in "${sarifPath}".`);
// This is always a configuration error, even for first-party runs.
throw new util_1.ConfigurationError(`No SARIF files found to upload in "${sarifPath}".`);
}
}
else {
@ -504,7 +506,8 @@ function validateUniqueCategory(sarif) {
for (const [category, { id, tool }] of Object.entries(categories)) {
const sentinelEnvVar = `CODEQL_UPLOAD_SARIF_${category}`;
if (process.env[sentinelEnvVar]) {
throw new InvalidSarifUploadError("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job per tool/category. " +
// This is always a configuration error, even for first-party runs.
throw new util_1.ConfigurationError("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job per tool/category. " +
"The easiest fix is to specify a unique value for the `category` input. If .runs[].automationDetails.id is specified " +
"in the sarif file, that will take precedence over your configured `category`. " +
`Category: (${id ? id : "none"}) Tool: (${tool ? tool : "none"})`);