]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve syntax error output from "arc liberate"
authorepriestley <git@epriestley.com>
Wed, 6 Jun 2012 17:53:02 +0000 (10:53 -0700)
committerepriestley <git@epriestley.com>
Wed, 6 Jun 2012 17:53:02 +0000 (10:53 -0700)
Summary:
Currently, when a file has a syntax error and you run "arc liberate", the symbol analyzer will fail and throw, which will make the mapper fail and throw, which will make arc fail and throw. This gives you a stack trace pile three scripts deep which is a giant pain to analyze visually.

Instead, raise a clear message.

Test Plan: Ran "arc liberate" with a syntax error. Got useful diagnostic output instead of 30 pages of stack mess.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran
Differential Revision: https://secure.phabricator.com/D2659

scripts/phutil_rebuild_map.php
scripts/phutil_symbols.php

index bd9a66211ed6d7084c0113035e6103a827e0ddc1..865f30dceffed277031d107e3e29e537dfb614f4 100755 (executable)
@@ -230,8 +230,18 @@ final class PhutilLibraryMapBuilder {
       $this->log("Analyzing {$count} files with {$limit} subprocesses...\n");
 
       foreach (Futures($futures)->limit($limit) as $file => $future) {
+        $result = $future->resolveJSON();
+        if (empty($result['error'])) {
+          $symbol_map[$file] = $result;
+        } else {
+          echo phutil_console_format(
+            "\n**SYNTAX ERROR!**\nFile: %s\nLine: %d\n\n%s\n",
+            Filesystem::readablePath($result['file']),
+            $result['line'],
+            $result['error']);
+          exit(1);
+        }
         $this->log(".");
-        $symbol_map[$file] = $future->resolveJSON();
       }
       $this->log("\nDone.\n");
     }
index 8e1b22293cc723738bc74e4967f1e1e1bcfa7137..282535969f88b0c54274219badc154291dc3d0d2 100755 (executable)
@@ -75,7 +75,20 @@ $path = Filesystem::resolvePath(head($paths));
 $show_all = $args->getArg('all');
 
 $source_code = Filesystem::readFile($path);
-$tree = XHPASTTree::newFromData($source_code);
+
+try {
+  $tree = XHPASTTree::newFromData($source_code);
+} catch (XHPASTSyntaxErrorException $ex) {
+  $result = array(
+    'error' => $ex->getMessage(),
+    'line'  => $ex->getErrorLine(),
+    'file'  => $path,
+  );
+  $json = new PhutilJSON();
+  echo $json->encodeFormatted($result);
+  exit(0);
+}
+
 $root = $tree->getRootNode();
 
 $root->buildSelectCache();