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

Improve error messages when trying to parse bad .arcconfig files.

Summary: Haiping is getting a pretty confusing error message when trying to
commit.

Test Plan: Created a mock repository, installed the hook, made commits against
directories with bad .arcconfigs.

Reviewers:

CC:
This commit is contained in:
epriestley 2011-02-24 16:34:27 -08:00
parent c13147cf53
commit 651f567f96
5 changed files with 25 additions and 15 deletions

View file

@ -82,10 +82,13 @@ try {
if ($config_trace_mode) { if ($config_trace_mode) {
echo "Loading phutil library '{$name}' from '{$location}'...\n"; echo "Loading phutil library '{$name}' from '{$location}'...\n";
} }
$library_root = Filesystem::resolvePath( $resolved_location = Filesystem::resolvePath(
$location, $location,
$working_copy->getProjectRoot()); $working_copy->getProjectRoot());
phutil_load_library($library_root); if (Filesystem::pathExists($resolved_location)) {
$location = $resolved_location;
}
phutil_load_library($location);
} }
} }

View file

@ -190,7 +190,8 @@ EOTEXT
$working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile( $working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile(
$project_root, $project_root,
$config); $config,
$config_file." (svnlook: {$transaction} {$repository})");
$lint_engine = $working_copy->getConfig('lint_engine'); $lint_engine = $working_copy->getConfig('lint_engine');
if (!$lint_engine) { if (!$lint_engine) {

View file

@ -36,24 +36,30 @@ class ArcanistWorkingCopyIdentity {
continue; continue;
} }
$proj_raw = Filesystem::readFile($config_file); $proj_raw = Filesystem::readFile($config_file);
$config = self::parseRawConfigFile($proj_raw); $config = self::parseRawConfigFile($proj_raw, $config_file);
$project_root = $dir; $project_root = $dir;
break; break;
} }
return new ArcanistWorkingCopyIdentity($project_root, $config); return new ArcanistWorkingCopyIdentity($project_root, $config);
} }
public static function newFromRootAndConfigFile($root, $config_raw) { public static function newFromRootAndConfigFile(
$config = self::parseRawConfigFile($config_raw); $root,
$config_raw,
$from_where) {
$config = self::parseRawConfigFile($config_raw, $from_where);
return new ArcanistWorkingCopyIdentity($root, $config); return new ArcanistWorkingCopyIdentity($root, $config);
} }
private static function parseRawConfigFile($raw_config) { private static function parseRawConfigFile($raw_config, $from_where) {
$proj = json_decode($raw_config, true); $proj = json_decode($raw_config, true);
if (!is_array($proj)) { if (!is_array($proj)) {
throw new Exception( throw new Exception(
"Unable to parse '.arcconfig' file in '{$dir}'. The file contents ". "Unable to parse '.arcconfig' file '{$from_where}'. The file contents ".
"should be valid JSON."); "should be valid JSON.\n\n".
"FILE CONTENTS\n".
substr($raw_config, 0, 2048));
} }
$required_keys = array( $required_keys = array(
'project_id', 'project_id',
@ -61,8 +67,8 @@ class ArcanistWorkingCopyIdentity {
foreach ($required_keys as $key) { foreach ($required_keys as $key) {
if (!array_key_exists($key, $proj)) { if (!array_key_exists($key, $proj)) {
throw new Exception( throw new Exception(
"Required key '{$key}' is missing from '.arcconfig' file in ". "Required key '{$key}' is missing from '.arcconfig' file ".
"'{$dir}'."); "'{$from_where}'.");
} }
} }
return $proj; return $proj;