1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00

Add option to symbol import script to ignore errors in input

Summary:
I was running the generate_ctags_symbols script on a project, and some
combination of this script and ctags was generating invalid rows for this
script. It's nice if this script can ignore invalid input instead of having
to add another step to filter out invalid input.

Test Plan: run script with input that has some invalid lines

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3532
This commit is contained in:
Nick Harper 2012-09-27 15:36:38 -07:00
parent 5a5d0b2b56
commit d591007d27
2 changed files with 78 additions and 60 deletions

View file

@ -73,6 +73,11 @@ foreach (Futures($futures)->limit(8) as $file => $future) {
list($token, $file_path, $line_num) = $tag_info; list($token, $file_path, $line_num) = $tag_info;
list($type, $language, $context) = $extension_fields; list($type, $language, $context) = $extension_fields;
// skip lines with tokens containing a space
if (strpos($token, ' ') !== false) {
continue;
}
// strip "language:" // strip "language:"
$language = substr($language, 9); $language = substr($language, 9);

View file

@ -35,6 +35,11 @@ $args->parse(
'help' => 'Do not clear all symbols for this project before '. 'help' => 'Do not clear all symbols for this project before '.
'uploading new symbols. Useful for incremental updating.', 'uploading new symbols. Useful for incremental updating.',
), ),
array(
'name' => 'ignore-errors',
'help' => 'If a line can\'t be parsed, ignore that line and '.
'continue instead of exiting.',
),
array( array(
'name' => 'more', 'name' => 'more',
'wildcard' => true, 'wildcard' => true,
@ -66,6 +71,7 @@ $input = explode("\n", $input);
$symbols = array(); $symbols = array();
foreach ($input as $key => $line) { foreach ($input as $key => $line) {
try {
$line_no = $key + 1; $line_no = $key + 1;
$matches = null; $matches = null;
$ok = preg_match( $ok = preg_match(
@ -101,14 +107,14 @@ foreach ($input as $key => $line) {
if (strlen($name) > 128) { if (strlen($name) > 128) {
throw new Exception( throw new Exception(
"Symbol name '{$name}' defined on line #{$line_no} is too long, maximum ". "Symbol name '{$name}' defined on line #{$line_no} is too long, ".
"symbol name length is 128 characters."); "maximum symbol name length is 128 characters.");
} }
if (strlen($type) > 12) { if (strlen($type) > 12) {
throw new Exception( throw new Exception(
"Symbol type '{$type}' defined on line #{$line_no} is too long, maximum ". "Symbol type '{$type}' defined on line #{$line_no} is too long, ".
"symbol type length is 12 characters."); "maximum symbol type length is 12 characters.");
} }
if (strlen($lang) > 32) { if (strlen($lang) > 32) {
@ -119,7 +125,7 @@ foreach ($input as $key => $line) {
if (!strlen($path) || $path[0] != 0) { if (!strlen($path) || $path[0] != 0) {
throw new Exception( throw new Exception(
"Path '{$path}' defined on line #{$line_no} is invalid. Paths should be ". "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ".
"begin with '/' and specify a path from the root of the project, like ". "begin with '/' and specify a path from the root of the project, like ".
"'/src/utils/utils.php'."); "'/src/utils/utils.php'.");
} }
@ -132,6 +138,13 @@ foreach ($input as $key => $line) {
'line' => $line_number, 'line' => $line_number,
'path' => $path, 'path' => $path,
); );
} catch (Exception $e) {
if ($args->getArg('ignore-errors')) {
continue;
} else {
throw $e;
}
}
} }
echo "Looking up path IDs...\n"; echo "Looking up path IDs...\n";