]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve error messages when trying to parse bad .arcconfig files.
authorepriestley <epriestley@phabricator.com>
Fri, 25 Feb 2011 00:34:27 +0000 (16:34 -0800)
committerepriestley <epriestley@phabricator.com>
Fri, 25 Feb 2011 00:34:27 +0000 (16:34 -0800)
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:

scripts/arcanist.php
src/repository/api/subversion/ArcanistSubversionAPI.php
src/workflow/diff/ArcanistDiffWorkflow.php
src/workflow/svn-hook-pre-commit/ArcanistSvnHookPreCommitWorkflow.php
src/workingcopyidentity/ArcanistWorkingCopyIdentity.php

index dfd7309e7d8abc1aecc34509bcb2354592ec4d0a..c3ec430887fc281d6c700b4411893f58ced41e5c 100755 (executable)
@@ -82,10 +82,13 @@ try {
       if ($config_trace_mode) {
         echo "Loading phutil library '{$name}' from '{$location}'...\n";
       }
-      $library_root = Filesystem::resolvePath(
+      $resolved_location = Filesystem::resolvePath(
         $location,
         $working_copy->getProjectRoot());
-      phutil_load_library($library_root);
+      if (Filesystem::pathExists($resolved_location)) {
+        $location = $resolved_location;
+      }
+      phutil_load_library($location);
     }
   }
 
index 7d4cef26261a0b8baf4e2622cf9cdda5d513dabb..4dd7fa7e4887e5b3463b66d3303810c14a321a1e 100644 (file)
@@ -29,7 +29,7 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
 
   protected $svnInfoRaw = array();
   protected $svnDiffRaw = array();
-  
+
   private $svnBaseRevisionNumber;
 
   public function getSourceControlSystemName() {
@@ -165,7 +165,7 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
     $info = $this->getSVNInfo('/');
     return $info['URL'].'@'.$this->getSVNBaseRevisionNumber();
   }
-  
+
   public function getSVNBaseRevisionNumber() {
     if ($this->svnBaseRevisionNumber) {
       return $this->svnBaseRevisionNumber;
@@ -173,7 +173,7 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
     $info = $this->getSVNInfo('/');
     return $info['Revision'];
   }
-  
+
   public function overrideSVNBaseRevisionNumber($effective_base_revision) {
     $this->svnBaseRevisionNumber = $effective_base_revision;
     return $this;
index a1d75ef510af6902c2bb0dd1c6db144a698c4554..3eb23bb10451fd3b5a249c5772a38cc9d2d693ca 100644 (file)
@@ -522,7 +522,7 @@ EOTEXT
               $revlist);
           }
         }
-        
+
         // If you have a change which affects several files, all of which are
         // at a consistent base revision, treat that revision as the effective
         // base revision. The use case here is that you made a change to some
index 6862092879f592a3f644d41823b9a0eb3ab0d5f4..f0caaefb1eeecbe10ea7fde90b5a5ece21c12cae 100644 (file)
@@ -190,7 +190,8 @@ EOTEXT
 
     $working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile(
       $project_root,
-      $config);
+      $config,
+      $config_file." (svnlook: {$transaction} {$repository})");
 
     $lint_engine = $working_copy->getConfig('lint_engine');
     if (!$lint_engine) {
index 76992e9c054a06d6dda444de12de707594a5848e..7763ac9a110b5de9f3b693179207a62fd215794d 100644 (file)
@@ -36,24 +36,30 @@ class ArcanistWorkingCopyIdentity {
         continue;
       }
       $proj_raw = Filesystem::readFile($config_file);
-      $config = self::parseRawConfigFile($proj_raw);
+      $config = self::parseRawConfigFile($proj_raw, $config_file);
       $project_root = $dir;
       break;
     }
     return new ArcanistWorkingCopyIdentity($project_root, $config);
   }
 
-  public static function newFromRootAndConfigFile($root, $config_raw) {
-    $config = self::parseRawConfigFile($config_raw);
+  public static function newFromRootAndConfigFile(
+    $root,
+    $config_raw,
+    $from_where) {
+
+    $config = self::parseRawConfigFile($config_raw, $from_where);
     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);
     if (!is_array($proj)) {
       throw new Exception(
-        "Unable to parse '.arcconfig' file in '{$dir}'. The file contents ".
-        "should be valid JSON.");
+        "Unable to parse '.arcconfig' file '{$from_where}'. The file contents ".
+        "should be valid JSON.\n\n".
+        "FILE CONTENTS\n".
+        substr($raw_config, 0, 2048));
     }
     $required_keys = array(
       'project_id',
@@ -61,8 +67,8 @@ class ArcanistWorkingCopyIdentity {
     foreach ($required_keys as $key) {
       if (!array_key_exists($key, $proj)) {
         throw new Exception(
-          "Required key '{$key}' is missing from '.arcconfig' file in ".
-          "'{$dir}'.");
+          "Required key '{$key}' is missing from '.arcconfig' file ".
+          "'{$from_where}'.");
       }
     }
     return $proj;