mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-08 07:52:39 +01:00
Improve error handling in ArcanistRuntime when failing to load libraries
Summary: Ref T13490. This fixes one bug in D21025 (loading relative to "arcanist/" rather than the parent directory) and improves behavior when a library fails to load (we prompt the user to continue). Test Plan: - Ran `arc list` with bad library specifications, got a sensible error and an option to continue. - Ran `arc list` with a library specification that existed next to "arcanist/", got a library load instead of an error. Maniphest Tasks: T13490 Differential Revision: https://secure.phabricator.com/D21029
This commit is contained in:
parent
9cd72baae9
commit
9bd5c23b2a
3 changed files with 41 additions and 31 deletions
|
@ -207,6 +207,10 @@ final class PhutilBootloader {
|
|||
$this->executeInclude($path);
|
||||
}
|
||||
|
||||
public function loadLibrary($path) {
|
||||
$this->executeInclude($path.'/__phutil_library_init__.php');
|
||||
}
|
||||
|
||||
private function executeInclude($path) {
|
||||
// Include the source using `include_once`, but convert any warnings or
|
||||
// recoverable errors into exceptions.
|
||||
|
|
|
@ -49,5 +49,5 @@ function phutil_deprecated($what, $why) {
|
|||
}
|
||||
|
||||
function phutil_load_library($path) {
|
||||
require_once $path.'/__phutil_library_init__.php';
|
||||
PhutilBootloader::getInstance()->loadLibrary($path);
|
||||
}
|
||||
|
|
|
@ -410,7 +410,7 @@ final class ArcanistRuntime {
|
|||
|
||||
if (!$resolved) {
|
||||
$arcanist_root = phutil_get_library_root('arcanist');
|
||||
$arcanist_root = dirname($arcanist_root);
|
||||
$arcanist_root = dirname(dirname($arcanist_root));
|
||||
$resolved_location = Filesystem::resolvePath(
|
||||
$location,
|
||||
$arcanist_root);
|
||||
|
@ -427,23 +427,6 @@ final class ArcanistRuntime {
|
|||
$error = null;
|
||||
try {
|
||||
phutil_load_library($location);
|
||||
} catch (PhutilBootloaderException $ex) {
|
||||
fwrite(
|
||||
STDERR,
|
||||
'%s',
|
||||
tsprintf(
|
||||
"**<bg:red> %s </bg>** %s\n",
|
||||
pht(
|
||||
'Failed to load phutil library at location "%s". This library '.
|
||||
'is specified by "%s". Check that the setting is correct and '.
|
||||
'the library is located in the right place.',
|
||||
$location,
|
||||
$description)));
|
||||
|
||||
$prompt = pht('Continue without loading library?');
|
||||
if (!phutil_console_confirm($prompt)) {
|
||||
throw $ex;
|
||||
}
|
||||
} catch (PhutilLibraryConflictException $ex) {
|
||||
if ($ex->getLibrary() != 'arcanist') {
|
||||
throw $ex;
|
||||
|
@ -462,19 +445,42 @@ final class ArcanistRuntime {
|
|||
// workflows more easily. For some context, see PHI13.
|
||||
|
||||
$executing_directory = dirname(dirname(__FILE__));
|
||||
$working_directory = dirname($location);
|
||||
|
||||
fwrite(
|
||||
STDERR,
|
||||
tsprintf(
|
||||
"**<bg:yellow> %s </bg>** %s\n",
|
||||
pht('VERY META'),
|
||||
pht(
|
||||
'You are running one copy of Arcanist (at path "%s") against '.
|
||||
'another copy of Arcanist (at path "%s"). Code in the current '.
|
||||
'working directory will not be loaded or executed.',
|
||||
$executing_directory,
|
||||
$working_directory)));
|
||||
$log->writeWarn(
|
||||
pht('VERY META'),
|
||||
pht(
|
||||
'You are running one copy of Arcanist (at path "%s") against '.
|
||||
'another copy of Arcanist (at path "%s"). Code in the current '.
|
||||
'working directory will not be loaded or executed.',
|
||||
$executing_directory,
|
||||
$working_directory));
|
||||
} catch (PhutilBootloaderException $ex) {
|
||||
$log->writeError(
|
||||
pht('LIBRARY ERROR'),
|
||||
pht(
|
||||
'Failed to load library at location "%s". This library '.
|
||||
'is specified by "%s". Check that the library is up to date.',
|
||||
$location,
|
||||
$description));
|
||||
|
||||
$prompt = pht('Continue without loading library?');
|
||||
if (!phutil_console_confirm($prompt)) {
|
||||
throw $ex;
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
$log->writeError(
|
||||
pht('LOAD ERROR'),
|
||||
pht(
|
||||
'Failed to load library at location "%s". This library is '.
|
||||
'specified by "%s". Check that the setting is correct and the '.
|
||||
'library is located in the right place.',
|
||||
$location,
|
||||
$description));
|
||||
|
||||
$prompt = pht('Continue without loading library?');
|
||||
if (!phutil_console_confirm($prompt)) {
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue