1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Create a custom exception class for missing linter dependencies

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
This commit is contained in:
Joshua Spence 2015-01-06 22:45:44 +11:00
parent 0b51f4d7c9
commit 6eed5c2514
7 changed files with 15 additions and 8 deletions

View file

@ -125,6 +125,7 @@ phutil_register_library_map(array(
'ArcanistMercurialParserTestCase' => 'repository/parser/__tests__/ArcanistMercurialParserTestCase.php', 'ArcanistMercurialParserTestCase' => 'repository/parser/__tests__/ArcanistMercurialParserTestCase.php',
'ArcanistMergeConflictLinter' => 'lint/linter/ArcanistMergeConflictLinter.php', 'ArcanistMergeConflictLinter' => 'lint/linter/ArcanistMergeConflictLinter.php',
'ArcanistMergeConflictLinterTestCase' => 'lint/linter/__tests__/ArcanistMergeConflictLinterTestCase.php', 'ArcanistMergeConflictLinterTestCase' => 'lint/linter/__tests__/ArcanistMergeConflictLinterTestCase.php',
'ArcanistMissingLinterException' => 'lint/linter/ArcanistMissingLinterException.php',
'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php', 'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php', 'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php', 'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
@ -308,6 +309,7 @@ phutil_register_library_map(array(
'ArcanistMercurialParserTestCase' => 'ArcanistTestCase', 'ArcanistMercurialParserTestCase' => 'ArcanistTestCase',
'ArcanistMergeConflictLinter' => 'ArcanistLinter', 'ArcanistMergeConflictLinter' => 'ArcanistLinter',
'ArcanistMergeConflictLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ArcanistMergeConflictLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistMissingLinterException' => 'Exception',
'ArcanistNoEffectException' => 'ArcanistUsageException', 'ArcanistNoEffectException' => 'ArcanistUsageException',
'ArcanistNoEngineException' => 'ArcanistUsageException', 'ArcanistNoEngineException' => 'ArcanistUsageException',
'ArcanistNoLintLinter' => 'ArcanistLinter', 'ArcanistNoLintLinter' => 'ArcanistLinter',

View file

@ -265,7 +265,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
if ($interpreter) { if ($interpreter) {
if (!Filesystem::binaryExists($interpreter)) { if (!Filesystem::binaryExists($interpreter)) {
throw new ArcanistUsageException( throw new ArcanistMissingLinterException(
pht( pht(
'Unable to locate interpreter "%s" to run linter %s. You may need '. 'Unable to locate interpreter "%s" to run linter %s. You may need '.
'to install the interpreter, or adjust your linter configuration.', 'to install the interpreter, or adjust your linter configuration.',
@ -273,7 +273,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
get_class($this))); get_class($this)));
} }
if (!Filesystem::pathExists($binary)) { if (!Filesystem::pathExists($binary)) {
throw new ArcanistUsageException( throw new ArcanistMissingLinterException(
sprintf( sprintf(
"%s\n%s", "%s\n%s",
pht( pht(
@ -287,7 +287,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
} }
} else { } else {
if (!Filesystem::binaryExists($binary)) { if (!Filesystem::binaryExists($binary)) {
throw new ArcanistUsageException( throw new ArcanistMissingLinterException(
sprintf( sprintf(
"%s\n%s", "%s\n%s",
pht( pht(

View file

@ -148,7 +148,7 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
if (!is_array($errors)) { if (!is_array($errors)) {
// Something went wrong and we can't decode the output. Exit abnormally. // Something went wrong and we can't decode the output. Exit abnormally.
throw new ArcanistUsageException( throw new RuntimeException(
"JSHint returned unparseable output.\n". "JSHint returned unparseable output.\n".
"stdout:\n\n{$stdout}". "stdout:\n\n{$stdout}".
"stderr:\n\n{$stderr}"); "stderr:\n\n{$stderr}");

View file

@ -0,0 +1,3 @@
<?php
final class ArcanistMissingLinterException extends Exception {}

View file

@ -108,7 +108,7 @@ final class ArcanistPyLintLinter extends ArcanistLinter {
list($err) = exec_manual('which %s', $pylint_bin); list($err) = exec_manual('which %s', $pylint_bin);
if ($err) { if ($err) {
throw new ArcanistUsageException( throw new ArcanistMissingLinterException(
"PyLint does not appear to be installed on this system. Install it ". "PyLint does not appear to be installed on this system. Install it ".
"(e.g., with 'sudo easy_install pylint') or configure ". "(e.g., with 'sudo easy_install pylint') or configure ".
"'lint.pylint.prefix' in your .arcconfig to point to the directory ". "'lint.pylint.prefix' in your .arcconfig to point to the directory ".

View file

@ -8,7 +8,7 @@ abstract class ArcanistExternalLinterTestCase extends ArcanistLinterTestCase {
$this->assertTrue( $this->assertTrue(
$version !== false, $version !== false,
pht('Failed to parse version from command.')); pht('Failed to parse version from command.'));
} catch (ArcanistUsageException $ex) { } catch (ArcanistMissingLinterException $ex) {
$this->assertSkipped($ex->getMessage()); $this->assertSkipped($ex->getMessage());
} }
} }

View file

@ -145,13 +145,15 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
if ($exception instanceof PhutilAggregateException) { if ($exception instanceof PhutilAggregateException) {
$caught_exception = false; $caught_exception = false;
foreach ($exception->getExceptions() as $ex) { foreach ($exception->getExceptions() as $ex) {
if ($ex instanceof ArcanistUsageException) { if ($ex instanceof ArcanistUsageException ||
$ex instanceof ArcanistMissingLinterException) {
$this->assertSkipped($ex->getMessage()); $this->assertSkipped($ex->getMessage());
} else { } else {
$caught_exception = true; $caught_exception = true;
} }
} }
} else if ($exception instanceof ArcanistUsageException) { } else if ($exception instanceof ArcanistUsageException ||
$exception instanceof ArcanistMissingLinterException) {
$this->assertSkipped($exception->getMessage()); $this->assertSkipped($exception->getMessage());
} }
$exception_message = $exception->getMessage()."\n\n". $exception_message = $exception->getMessage()."\n\n".