1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +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($type, $language, $context) = $extension_fields;
// skip lines with tokens containing a space
if (strpos($token, ' ') !== false) {
continue;
}
// strip "language:"
$language = substr($language, 9);

View file

@ -35,6 +35,11 @@ $args->parse(
'help' => 'Do not clear all symbols for this project before '.
'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(
'name' => 'more',
'wildcard' => true,
@ -66,6 +71,7 @@ $input = explode("\n", $input);
$symbols = array();
foreach ($input as $key => $line) {
try {
$line_no = $key + 1;
$matches = null;
$ok = preg_match(
@ -101,14 +107,14 @@ foreach ($input as $key => $line) {
if (strlen($name) > 128) {
throw new Exception(
"Symbol name '{$name}' defined on line #{$line_no} is too long, maximum ".
"symbol name length is 128 characters.");
"Symbol name '{$name}' defined on line #{$line_no} is too long, ".
"maximum symbol name length is 128 characters.");
}
if (strlen($type) > 12) {
throw new Exception(
"Symbol type '{$type}' defined on line #{$line_no} is too long, maximum ".
"symbol type length is 12 characters.");
"Symbol type '{$type}' defined on line #{$line_no} is too long, ".
"maximum symbol type length is 12 characters.");
}
if (strlen($lang) > 32) {
@ -119,7 +125,7 @@ foreach ($input as $key => $line) {
if (!strlen($path) || $path[0] != 0) {
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 ".
"'/src/utils/utils.php'.");
}
@ -132,6 +138,13 @@ foreach ($input as $key => $line) {
'line' => $line_number,
'path' => $path,
);
} catch (Exception $e) {
if ($args->getArg('ignore-errors')) {
continue;
} else {
throw $e;
}
}
}
echo "Looking up path IDs...\n";