]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Create a custom exception class for missing linter dependencies
authorJoshua Spence <josh@joshuaspence.com>
Tue, 6 Jan 2015 11:45:44 +0000 (22:45 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Tue, 6 Jan 2015 11:51:17 +0000 (22:51 +1100)
Summary: I feel that we are abusing `ArcanistUsageException`. Throw a more tailed exception instead. Depends on D11197.

Test Plan: `arc lint`, I guess.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: avivey, Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11205

src/__phutil_library_map__.php
src/lint/linter/ArcanistExternalLinter.php
src/lint/linter/ArcanistJSHintLinter.php
src/lint/linter/ArcanistMissingLinterException.php [new file with mode: 0644]
src/lint/linter/ArcanistPyLintLinter.php
src/lint/linter/__tests__/ArcanistExternalLinterTestCase.php
src/lint/linter/__tests__/ArcanistLinterTestCase.php

index 2844716ef3522d0fdda1ea3fb9723f41ea2ff51d..aabdc23288615257aa9835e42ead0081814e2af0 100644 (file)
@@ -125,6 +125,7 @@ phutil_register_library_map(array(
     'ArcanistMercurialParserTestCase' => 'repository/parser/__tests__/ArcanistMercurialParserTestCase.php',
     'ArcanistMergeConflictLinter' => 'lint/linter/ArcanistMergeConflictLinter.php',
     'ArcanistMergeConflictLinterTestCase' => 'lint/linter/__tests__/ArcanistMergeConflictLinterTestCase.php',
+    'ArcanistMissingLinterException' => 'lint/linter/ArcanistMissingLinterException.php',
     'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
     'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
     'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
@@ -308,6 +309,7 @@ phutil_register_library_map(array(
     'ArcanistMercurialParserTestCase' => 'ArcanistTestCase',
     'ArcanistMergeConflictLinter' => 'ArcanistLinter',
     'ArcanistMergeConflictLinterTestCase' => 'ArcanistArcanistLinterTestCase',
+    'ArcanistMissingLinterException' => 'Exception',
     'ArcanistNoEffectException' => 'ArcanistUsageException',
     'ArcanistNoEngineException' => 'ArcanistUsageException',
     'ArcanistNoLintLinter' => 'ArcanistLinter',
index bb907d57f930b88c667291cae23fd04eb58037d2..bcb7e1afe7408064dc28cccd6f554491111be832 100644 (file)
@@ -265,7 +265,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
 
     if ($interpreter) {
       if (!Filesystem::binaryExists($interpreter)) {
-        throw new ArcanistUsageException(
+        throw new ArcanistMissingLinterException(
           pht(
             'Unable to locate interpreter "%s" to run linter %s. You may need '.
             'to install the interpreter, or adjust your linter configuration.',
@@ -273,7 +273,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
             get_class($this)));
       }
       if (!Filesystem::pathExists($binary)) {
-        throw new ArcanistUsageException(
+        throw new ArcanistMissingLinterException(
           sprintf(
             "%s\n%s",
             pht(
@@ -287,7 +287,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
       }
     } else {
       if (!Filesystem::binaryExists($binary)) {
-        throw new ArcanistUsageException(
+        throw new ArcanistMissingLinterException(
           sprintf(
             "%s\n%s",
             pht(
index 7884ef512d9c3d323a39e970d025ca7592538cd5..ea18e7714794da0b1553374717f9c326c8ab32b2 100644 (file)
@@ -148,7 +148,7 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
 
     if (!is_array($errors)) {
       // Something went wrong and we can't decode the output. Exit abnormally.
-      throw new ArcanistUsageException(
+      throw new RuntimeException(
         "JSHint returned unparseable output.\n".
         "stdout:\n\n{$stdout}".
         "stderr:\n\n{$stderr}");
diff --git a/src/lint/linter/ArcanistMissingLinterException.php b/src/lint/linter/ArcanistMissingLinterException.php
new file mode 100644 (file)
index 0000000..a86f56a
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+final class ArcanistMissingLinterException extends Exception {}
index b758e8e4566c26a8fda40e483dd941394bb6f754..45ebf37fd0f4945ee1877a94fa58d79e08dc74f6 100644 (file)
@@ -108,7 +108,7 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
 
       list($err) = exec_manual('which %s', $pylint_bin);
       if ($err) {
-        throw new ArcanistUsageException(
+        throw new ArcanistMissingLinterException(
           "PyLint does not appear to be installed on this system. Install it ".
           "(e.g., with 'sudo easy_install pylint') or configure ".
           "'lint.pylint.prefix' in your .arcconfig to point to the directory ".
index 7036cf86e5644fc1266b441c452fbd13d375ca05..bd7407c19574592a5880be84f023174b6043dc92 100644 (file)
@@ -8,7 +8,7 @@ abstract class ArcanistExternalLinterTestCase extends ArcanistLinterTestCase {
       $this->assertTrue(
         $version !== false,
         pht('Failed to parse version from command.'));
-    } catch (ArcanistUsageException $ex) {
+    } catch (ArcanistMissingLinterException $ex) {
       $this->assertSkipped($ex->getMessage());
     }
   }
index 87a84c0c22e85dac59d2c28fd96c8c517206f7b6..3b019f218449accaa749b31cfde986ca1a3c805a 100644 (file)
@@ -145,13 +145,15 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       if ($exception instanceof PhutilAggregateException) {
         $caught_exception = false;
         foreach ($exception->getExceptions() as $ex) {
-          if ($ex instanceof ArcanistUsageException) {
+          if ($ex instanceof ArcanistUsageException ||
+              $ex instanceof ArcanistMissingLinterException) {
             $this->assertSkipped($ex->getMessage());
           } else {
             $caught_exception = true;
           }
         }
-      } else if ($exception instanceof ArcanistUsageException) {
+      } else if ($exception instanceof ArcanistUsageException ||
+                 $exception instanceof ArcanistMissingLinterException) {
         $this->assertSkipped($exception->getMessage());
       }
       $exception_message = $exception->getMessage()."\n\n".