]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Print lint results before throwing
authorvrana <jakubv@fb.com>
Sat, 20 Oct 2012 11:42:53 +0000 (04:42 -0700)
committervrana <jakubv@fb.com>
Sat, 20 Oct 2012 12:03:22 +0000 (05:03 -0700)
Summary:
When some linter throws then we don't print any result.
This is bad in case when the linter threw e.g. because of syntax error in some file which some other linter will tell us about.

Test Plan: Threw from a linter, made lint error in a file, saw error then exception.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3756

src/lint/engine/ArcanistLintEngine.php
src/workflow/ArcanistLintWorkflow.php

index 59a05d2ca9ba1121532b5f182808ac84e7f91e4b..8ea0755bc72b80e8f299a301674533f5b9b7646d 100644 (file)
@@ -196,44 +196,49 @@ abstract class ArcanistLintEngine {
       throw new ArcanistNoEffectException("No paths are lintable.");
     }
 
+    $exceptions = array();
     foreach ($linters as $linter) {
-      $linter->setEngine($this);
-      if (!$linter->canRun()) {
-        continue;
-      }
-      $paths = $linter->getPaths();
-
-      foreach ($paths as $key => $path) {
-        // Make sure each path has a result generated, even if it is empty
-        // (i.e., the file has no lint messages).
-        $result = $this->getResultForPath($path);
-        if (isset($stopped[$path])) {
-          unset($paths[$key]);
+      try {
+        $linter->setEngine($this);
+        if (!$linter->canRun()) {
+          continue;
         }
-      }
-      $paths = array_values($paths);
-
-      if ($paths) {
-        $linter->willLintPaths($paths);
-        foreach ($paths as $path) {
-          $linter->willLintPath($path);
-          $linter->lintPath($path);
-          if ($linter->didStopAllLinters()) {
-            $stopped[$path] = true;
+        $paths = $linter->getPaths();
+
+        foreach ($paths as $key => $path) {
+          // Make sure each path has a result generated, even if it is empty
+          // (i.e., the file has no lint messages).
+          $result = $this->getResultForPath($path);
+          if (isset($stopped[$path])) {
+            unset($paths[$key]);
           }
         }
-      }
-
-      $minimum = $this->minimumSeverity;
-      foreach ($linter->getLintMessages() as $message) {
-        if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
-          continue;
+        $paths = array_values($paths);
+
+        if ($paths) {
+          $linter->willLintPaths($paths);
+          foreach ($paths as $path) {
+            $linter->willLintPath($path);
+            $linter->lintPath($path);
+            if ($linter->didStopAllLinters()) {
+              $stopped[$path] = true;
+            }
+          }
         }
-        if (!$this->isRelevantMessage($message)) {
-          continue;
+
+        $minimum = $this->minimumSeverity;
+        foreach ($linter->getLintMessages() as $message) {
+          if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
+            continue;
+          }
+          if (!$this->isRelevantMessage($message)) {
+            continue;
+          }
+          $result = $this->getResultForPath($message->getPath());
+          $result->addMessage($message);
         }
-        $result = $this->getResultForPath($message->getPath());
-        $result->addMessage($message);
+      } catch (Exception $ex) {
+        $exceptions[] = $ex;
       }
     }
 
@@ -258,6 +263,14 @@ abstract class ArcanistLintEngine {
       }
     }
 
+    if ($exceptions) {
+      throw new PhutilAggregateException('Some linters failed:', $exceptions);
+    }
+
+    return $this->results;
+  }
+
+  public function getResults() {
     return $this->results;
   }
 
index 06e284a0a274e20ac4c1d2a97dd92a297ecdca2c..4c9c11a22e531c464e669fbfdf542ca4396b7dab 100644 (file)
@@ -201,7 +201,14 @@ EOTEXT
       $engine->setEnableAsyncLint(false);
     }
 
-    $results = $engine->run();
+    $failed = null;
+    try {
+      $engine->run();
+    } catch (Exception $ex) {
+      $failed = $ex;
+    }
+
+    $results = $engine->getResults();
 
     // It'd be nice to just return a single result from the run method above
     // which contains both the lint messages and the postponed linters.
@@ -309,6 +316,10 @@ EOTEXT
       }
     }
 
+    if ($failed) {
+      throw $failed;
+    }
+
     $repository_api = $this->getRepositoryAPI();
     if ($wrote_to_disk &&
         ($repository_api instanceof ArcanistGitAPI) &&