mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +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);
|
$this->executeInclude($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadLibrary($path) {
|
||||||
|
$this->executeInclude($path.'/__phutil_library_init__.php');
|
||||||
|
}
|
||||||
|
|
||||||
private function executeInclude($path) {
|
private function executeInclude($path) {
|
||||||
// Include the source using `include_once`, but convert any warnings or
|
// Include the source using `include_once`, but convert any warnings or
|
||||||
// recoverable errors into exceptions.
|
// recoverable errors into exceptions.
|
||||||
|
|
|
@ -49,5 +49,5 @@ function phutil_deprecated($what, $why) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function phutil_load_library($path) {
|
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) {
|
if (!$resolved) {
|
||||||
$arcanist_root = phutil_get_library_root('arcanist');
|
$arcanist_root = phutil_get_library_root('arcanist');
|
||||||
$arcanist_root = dirname($arcanist_root);
|
$arcanist_root = dirname(dirname($arcanist_root));
|
||||||
$resolved_location = Filesystem::resolvePath(
|
$resolved_location = Filesystem::resolvePath(
|
||||||
$location,
|
$location,
|
||||||
$arcanist_root);
|
$arcanist_root);
|
||||||
|
@ -427,23 +427,6 @@ final class ArcanistRuntime {
|
||||||
$error = null;
|
$error = null;
|
||||||
try {
|
try {
|
||||||
phutil_load_library($location);
|
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) {
|
} catch (PhutilLibraryConflictException $ex) {
|
||||||
if ($ex->getLibrary() != 'arcanist') {
|
if ($ex->getLibrary() != 'arcanist') {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
|
@ -462,19 +445,42 @@ final class ArcanistRuntime {
|
||||||
// workflows more easily. For some context, see PHI13.
|
// workflows more easily. For some context, see PHI13.
|
||||||
|
|
||||||
$executing_directory = dirname(dirname(__FILE__));
|
$executing_directory = dirname(dirname(__FILE__));
|
||||||
$working_directory = dirname($location);
|
|
||||||
|
|
||||||
fwrite(
|
$log->writeWarn(
|
||||||
STDERR,
|
pht('VERY META'),
|
||||||
tsprintf(
|
pht(
|
||||||
"**<bg:yellow> %s </bg>** %s\n",
|
'You are running one copy of Arcanist (at path "%s") against '.
|
||||||
pht('VERY META'),
|
'another copy of Arcanist (at path "%s"). Code in the current '.
|
||||||
pht(
|
'working directory will not be loaded or executed.',
|
||||||
'You are running one copy of Arcanist (at path "%s") against '.
|
$executing_directory,
|
||||||
'another copy of Arcanist (at path "%s"). Code in the current '.
|
$working_directory));
|
||||||
'working directory will not be loaded or executed.',
|
} catch (PhutilBootloaderException $ex) {
|
||||||
$executing_directory,
|
$log->writeError(
|
||||||
$working_directory)));
|
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