mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Throw InvalidRequestError if JSON parsing fails
This commit is contained in:
19
lib/upload-lib.js
generated
19
lib/upload-lib.js
generated
@@ -162,8 +162,7 @@ async function uploadFromActions(sarifPath, checkoutPath, category, logger, { is
|
||||
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 || e instanceof SyntaxError) &&
|
||||
isThirdPartyUpload) {
|
||||
if (e instanceof InvalidRequestError && isThirdPartyUpload) {
|
||||
throw new util_1.ConfigurationError(e.message);
|
||||
}
|
||||
throw e;
|
||||
@@ -189,13 +188,7 @@ function getSarifFilePaths(sarifPath) {
|
||||
// Counts the number of results in the given SARIF file
|
||||
function countResultsInSarif(sarif) {
|
||||
let numResults = 0;
|
||||
let parsedSarif;
|
||||
try {
|
||||
parsedSarif = JSON.parse(sarif);
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidRequestError(`Invalid SARIF. JSON syntax error: ${(0, util_1.wrapError)(e).message}`);
|
||||
}
|
||||
const parsedSarif = JSON.parse(sarif);
|
||||
if (!Array.isArray(parsedSarif.runs)) {
|
||||
throw new InvalidRequestError("Invalid SARIF. Missing 'runs' array.");
|
||||
}
|
||||
@@ -210,7 +203,13 @@ function countResultsInSarif(sarif) {
|
||||
// Validates that the given file path refers to a valid SARIF file.
|
||||
// Throws an error if the file is invalid.
|
||||
function validateSarifFileSchema(sarifFilePath, logger) {
|
||||
const sarif = JSON.parse(fs.readFileSync(sarifFilePath, "utf8"));
|
||||
let sarif;
|
||||
try {
|
||||
sarif = JSON.parse(fs.readFileSync(sarifFilePath, "utf8"));
|
||||
}
|
||||
catch (e) {
|
||||
throw new InvalidRequestError(`Invalid SARIF. JSON syntax error: ${(0, util_1.wrapError)(e).message}`);
|
||||
}
|
||||
const schema = require("../src/sarif-schema-2.1.0.json");
|
||||
const result = new jsonschema.Validator().validate(sarif, schema);
|
||||
// Filter errors related to invalid URIs in the artifactLocation field as this
|
||||
|
||||
Reference in New Issue
Block a user