mirror of
https://github.com/github/codeql-action.git
synced 2026-04-05 11:12:16 +00:00
Rename InvalidRequestError to InvalidSarifUploadError
Nitty: make it a little clearer when this shows up in the logs what type of request we mean
This commit is contained in:
@@ -37,7 +37,7 @@ function combineSarifFiles(sarifFiles: string[]): SarifFile {
|
||||
if (combinedSarif.version === null) {
|
||||
combinedSarif.version = sarifObject.version;
|
||||
} else if (combinedSarif.version !== sarifObject.version) {
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
`Different SARIF versions encountered: ${combinedSarif.version} and ${sarifObject.version}`,
|
||||
);
|
||||
}
|
||||
@@ -207,7 +207,7 @@ export async function uploadFromActions(
|
||||
logger,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidRequestError && isThirdPartyUpload) {
|
||||
if (e instanceof InvalidSarifUploadError && isThirdPartyUpload) {
|
||||
throw new ConfigurationError(e.message);
|
||||
}
|
||||
throw e;
|
||||
@@ -216,14 +216,14 @@ export async function uploadFromActions(
|
||||
|
||||
function getSarifFilePaths(sarifPath: string) {
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
throw new InvalidRequestError(`Path does not exist: ${sarifPath}`);
|
||||
throw new InvalidSarifUploadError(`Path does not exist: ${sarifPath}`);
|
||||
}
|
||||
|
||||
let sarifFiles: string[];
|
||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||
sarifFiles = findSarifFilesInDir(sarifPath);
|
||||
if (sarifFiles.length === 0) {
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
`No SARIF files found to upload in "${sarifPath}".`,
|
||||
);
|
||||
}
|
||||
@@ -238,12 +238,12 @@ function countResultsInSarif(sarif: string): number {
|
||||
let numResults = 0;
|
||||
const parsedSarif = JSON.parse(sarif);
|
||||
if (!Array.isArray(parsedSarif.runs)) {
|
||||
throw new InvalidRequestError("Invalid SARIF. Missing 'runs' array.");
|
||||
throw new InvalidSarifUploadError("Invalid SARIF. Missing 'runs' array.");
|
||||
}
|
||||
|
||||
for (const run of parsedSarif.runs) {
|
||||
if (!Array.isArray(run.results)) {
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
"Invalid SARIF. Missing 'results' array in run.",
|
||||
);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ export function validateSarifFileSchema(sarifFilePath: string, logger: Logger) {
|
||||
try {
|
||||
sarif = JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as SarifFile;
|
||||
} catch (e) {
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
`Invalid SARIF. JSON syntax error: ${wrapError(e).message}`,
|
||||
);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ export function validateSarifFileSchema(sarifFilePath: string, logger: Logger) {
|
||||
// Set the main error message to the stacks of all the errors.
|
||||
// This should be of a manageable size and may even give enough to fix the error.
|
||||
const sarifErrors = errors.map((e) => `- ${e.stack}`);
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
`Unable to upload "${sarifFilePath}" as it is not valid SARIF:\n${sarifErrors.join(
|
||||
"\n",
|
||||
)}`,
|
||||
@@ -511,7 +511,7 @@ export async function waitForProcessing(
|
||||
const message = `Code Scanning could not process the submitted SARIF file:\n${response.data.errors}`;
|
||||
throw shouldConsiderConfigurationError(response.data.errors as string[])
|
||||
? new ConfigurationError(message)
|
||||
: new InvalidRequestError(message);
|
||||
: new InvalidSarifUploadError(message);
|
||||
} else {
|
||||
util.assertNever(status);
|
||||
}
|
||||
@@ -588,7 +588,7 @@ export function validateUniqueCategory(sarif: SarifFile): void {
|
||||
for (const [category, { id, tool }] of Object.entries(categories)) {
|
||||
const sentinelEnvVar = `CODEQL_UPLOAD_SARIF_${category}`;
|
||||
if (process.env[sentinelEnvVar]) {
|
||||
throw new InvalidRequestError(
|
||||
throw new InvalidSarifUploadError(
|
||||
"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`. " +
|
||||
@@ -615,7 +615,7 @@ function sanitize(str?: string) {
|
||||
/**
|
||||
* An error that occurred due to an invalid SARIF upload request.
|
||||
*/
|
||||
class InvalidRequestError extends Error {
|
||||
class InvalidSarifUploadError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user