output a better error message

This commit is contained in:
Robert Brignull 2020-05-22 14:56:20 +01:00
parent ddee374101
commit ae301902e1
6 changed files with 35 additions and 21 deletions

18
lib/upload-lib.js generated
View file

@ -130,10 +130,20 @@ function validateSarifFileSchema(sarifFilePath) {
const schema = JSON.parse(fs.readFileSync(__dirname + '/../src/sarif_v2.1.0_schema.json', 'utf8'));
const result = new jsonschema.Validator().validate(sarif, schema);
if (result.valid) {
return [];
return true;
}
else {
return result.errors.map(e => e.message);
// Set the failure 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 errorMessages = result.errors.map(e => "- " + e.stack);
core.setFailed("Unable to upload \"" + sarifFilePath + "\" as it is not valid SARIF:\n" + errorMessages.join("\n"));
// Also output the more verbose error messages in groups as these may be very large.
for (const error of result.errors) {
core.startGroup("Error details: " + error.stack);
core.info(JSON.stringify(error, null, 2));
core.endGroup();
}
return false;
}
}
exports.validateSarifFileSchema = validateSarifFileSchema;
@ -152,9 +162,7 @@ async function uploadFiles(sarifFiles) {
core.exportVariable(sentinelEnvVar, sentinelEnvVar);
// Validate that the files we were asked to upload are all valid SARIF files
for (const file of sarifFiles) {
const errors = validateSarifFileSchema(file);
if (errors.length > 0) {
core.setFailed("Unable to upload \"" + file + "\" as it is not valid SARIF:\n" + errors.join("\n"));
if (!validateSarifFileSchema(file)) {
return false;
}
}