From d2bb8a1bb90a33e8317daf2f2932001af9f258c3 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 1 Aug 2018 11:39:07 -0700 Subject: [PATCH] Log warnings, fail on errors (#848) --- lib/RulesDeploy.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/RulesDeploy.js b/lib/RulesDeploy.js index 223c736a..40cb57dd 100644 --- a/lib/RulesDeploy.js +++ b/lib/RulesDeploy.js @@ -93,11 +93,11 @@ RulesDeploy.prototype = { var self = this; return gcp.rules.testRuleset(self.options.project, files).then(function(response) { if (response.body && response.body.issues && response.body.issues.length > 0) { - var add = response.body.issues.length === 1 ? "" : "s"; - var message = "Compilation error" + add + " in " + chalk.bold(filename) + ":\n"; + var warnings = []; + var errors = []; response.body.issues.forEach(function(issue) { - message += - "\n[" + + var issueMessage = + "[" + issue.severity.substring(0, 1) + "] " + issue.sourcePosition.line + @@ -105,9 +105,26 @@ RulesDeploy.prototype = { issue.sourcePosition.column + " - " + issue.description; + + if (issue.severity === "ERROR") { + errors.push(issueMessage); + } else { + warnings.push(issueMessage); + } }); - return utils.reject(message, { exit: 1 }); + if (warnings.length > 0) { + warnings.forEach(function(warning) { + utils.logWarning(warning); + }); + } + + if (errors.length > 0) { + var add = errors.length === 1 ? "" : "s"; + var message = + "Compilation error" + add + " in " + chalk.bold(filename) + ":\n" + errors.join("\n"); + return utils.reject(message, { exit: 1 }); + } } utils.logSuccess(