From 6f6fde84cc530c2b51f095d9636b9e15301519a1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 6 Jun 2012 10:53:02 -0700 Subject: [PATCH] Improve syntax error output from "arc liberate" 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 | 12 +++++++++++- scripts/phutil_symbols.php | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/phutil_rebuild_map.php b/scripts/phutil_rebuild_map.php index bd9a6621..865f30dc 100755 --- a/scripts/phutil_rebuild_map.php +++ b/scripts/phutil_rebuild_map.php @@ -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"); } diff --git a/scripts/phutil_symbols.php b/scripts/phutil_symbols.php index 8e1b2229..28253596 100755 --- a/scripts/phutil_symbols.php +++ b/scripts/phutil_symbols.php @@ -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();