mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Better handling of .arcconfig
files.
Summary: Throw a useful error message when an `.arcconfig` file is not valid JSON. Depends on D9697. Test Plan: Modified an `.arcconfig` file to be invalid JSON. ``` > arc lint Usage Exception: Your '~/.arcrc' file is not a valid JSON file. Parse error on line 18 at column 4: Expected: 'STRING' - It appears you have an extra trailing comma ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9681
This commit is contained in:
parent
30df78f64c
commit
750a94e89f
2 changed files with 32 additions and 27 deletions
|
@ -63,13 +63,13 @@ final class ArcanistConfigurationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For the advanced case where you want customized configuratin handling.
|
* For the advanced case where you want customized configuration handling.
|
||||||
*
|
*
|
||||||
* Reads the configuration from all available sources, returning a map (array)
|
* Reads the configuration from all available sources, returning a map (array)
|
||||||
* of results, with the source as key. Missing values will not be in the map,
|
* of results, with the source as key. Missing values will not be in the map,
|
||||||
* so an empty array will be returned if no results are found.
|
* so an empty array will be returned if no results are found.
|
||||||
*
|
*
|
||||||
* The map is ordered by the cannonical sources precedence, which is:
|
* The map is ordered by the canonical sources precedence, which is:
|
||||||
* runtime > local > project > user > system
|
* runtime > local > project > user > system
|
||||||
*
|
*
|
||||||
* @param key Key to read
|
* @param key Key to read
|
||||||
|
@ -198,10 +198,12 @@ final class ArcanistConfigurationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_config_data = Filesystem::readFile($user_config_path);
|
$user_config_data = Filesystem::readFile($user_config_path);
|
||||||
$user_config = json_decode($user_config_data, true);
|
try {
|
||||||
if (!is_array($user_config)) {
|
$user_config = phutil_json_decode($user_config_data);
|
||||||
throw new ArcanistUsageException(
|
} catch (PhutilJSONParserException $ex) {
|
||||||
"Your '~/.arcrc' file is not a valid JSON file.");
|
throw new PhutilProxyException(
|
||||||
|
"Your '~/.arcrc' file is not a valid JSON file.".
|
||||||
|
$ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$console->writeLog(
|
$console->writeLog(
|
||||||
|
@ -290,8 +292,14 @@ final class ArcanistConfigurationManager {
|
||||||
'Config: Reading system configuration file "%s"...',
|
'Config: Reading system configuration file "%s"...',
|
||||||
$system_config_path));
|
$system_config_path));
|
||||||
$file = Filesystem::readFile($system_config_path);
|
$file = Filesystem::readFile($system_config_path);
|
||||||
if ($file) {
|
try {
|
||||||
$system_config = json_decode($file, true);
|
$system_config = phutil_json_decode($file);
|
||||||
|
} catch (PhutilJSONParserException $ex) {
|
||||||
|
throw new PhutilProxyException(
|
||||||
|
pht(
|
||||||
|
"Your '%s' file is not a valid JSON file.",
|
||||||
|
$system_config_path),
|
||||||
|
$ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$console->writeLog(
|
$console->writeLog(
|
||||||
|
|
|
@ -201,17 +201,13 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function parseRawConfigFile($raw_config, $from_where) {
|
private static function parseRawConfigFile($raw_config, $from_where) {
|
||||||
$proj = json_decode($raw_config, true);
|
try {
|
||||||
|
return phutil_json_decode($raw_config);
|
||||||
if (!is_array($proj)) {
|
} catch (PhutilJSONParserException $ex) {
|
||||||
throw new Exception(
|
throw new PhutilProxyException(
|
||||||
"Unable to parse '.arcconfig' file '{$from_where}'. The file contents ".
|
pht("Unable to parse '.arcconfig' file '%s'.", $from_where),
|
||||||
"should be valid JSON.\n\n".
|
$ex);
|
||||||
"FILE CONTENTS\n".
|
|
||||||
substr($raw_config, 0, 2048));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $proj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function __construct($root, array $config) {
|
private function __construct($root, array $config) {
|
||||||
|
@ -297,15 +293,13 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
*
|
*
|
||||||
* @task config
|
* @task config
|
||||||
*/
|
*/
|
||||||
public function getLocalConfig($key, $default=null) {
|
public function getLocalConfig($key, $default = null) {
|
||||||
return idx($this->localConfig, $key, $default);
|
return idx($this->localConfig, $key, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readLocalArcConfig() {
|
public function readLocalArcConfig() {
|
||||||
if (strlen($this->localMetaDir)) {
|
if (strlen($this->localMetaDir)) {
|
||||||
$local_path = Filesystem::resolvePath(
|
$local_path = Filesystem::resolvePath('arc/config', $this->localMetaDir);
|
||||||
'arc/config',
|
|
||||||
$this->localMetaDir);
|
|
||||||
|
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
||||||
|
@ -316,9 +310,12 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
'Config: Reading local configuration file "%s"...',
|
'Config: Reading local configuration file "%s"...',
|
||||||
$local_path));
|
$local_path));
|
||||||
|
|
||||||
$file = Filesystem::readFile($local_path);
|
try {
|
||||||
if ($file) {
|
return phutil_json_decode($local_path);
|
||||||
return json_decode($file, true);
|
} catch (PhutilJSONParserException $ex) {
|
||||||
|
throw new PhutilProxyException(
|
||||||
|
pht("Failed to parse '%s' as JSON.", $local_path),
|
||||||
|
$ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$console->writeLog(
|
$console->writeLog(
|
||||||
|
@ -327,8 +324,8 @@ final class ArcanistWorkingCopyIdentity {
|
||||||
'Config: Did not find local configuration at "%s".',
|
'Config: Did not find local configuration at "%s".',
|
||||||
$local_path));
|
$local_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue