grom358 / pharborist

A PHP library to query and transform source code via tree operations.
GNU General Public License v3.0
44 stars 10 forks source link

Confusing error message when ExpressionParser::P encounters a ParserException #193

Closed webchick closed 9 years ago

webchick commented 9 years ago

Relevant code in the "else" branch:

  private function P() {
    $node = $this->next();
    if ($node instanceof Operator) {
      if ($node->hasUnaryMode) {
        $this->pushOperator($node, Operator::MODE_UNARY);
        $this->consume();
        $this->P();
      }
      else {
        throw new ParserException($node->getSourcePosition(), 'unexpected ' . $node->getOperator() . ' operator!');
      }
    }

I ended up hitting this when I had Twig debug mode turned on in my D8 site and attempted to run drush dmu-upgrade pants (see sister issue at https://www.drupal.org/node/2408745).

Drush outputs just:

"(Error at 3:1: unexpected < operator!)"

Which unfortunately, doesn't clue me in to what's wrong.

Would be great if this were something instead like:

"(Error at $filename, line 3:1: unexpected < operator in string $string!)"

Also, there may be a BUG bug with the fact that it died when it encountered comments in the source but I'm not sure if that's a Drupal problem, a Pharborist problem, or a DMU problem. Here's the backtrace in case it's helpful:

Error at 3:1: unexpected < operator!                                                              [error]
string(3649) "#0 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/ExpressionParser.php(82): Pharborist\ExpressionParser->P()
#1 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/ExpressionParser.php(74): Pharborist\ExpressionParser->E()
#2 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(1199): Pharborist\ExpressionParser->parse(Array)
#3 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(506): Pharborist\Parser->expr()
#4 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(465): Pharborist\Parser->exprStatement()
#5 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(342): Pharborist\Parser->statement()
#6 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(303): Pharborist\Parser->topStatement()
#7 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(192): Pharborist\Parser->topStatementList(Object(Pharborist\RootNode))
#8 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(225): Pharborist\Parser->buildTree(Object(Pharborist\TokenIterator))
#9 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/vendor/grom358/pharborist/src/Parser.php(235): Pharborist\Parser::parseSource('<?php \n\n<!-- TH...')
#10 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/src/ConverterBase.php(196): Pharborist\Parser::parseSnippet('\n\n<!-- THEME DE...')
#11 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/src/Plugin/DMU/Routing/ContentRoute.php(238): Drupal\drupalmoduleupgrader\ConverterBase->parse(Array)
#12 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/src/Plugin/DMU/Routing/ContentRoute.php(133): Drupal\drupalmoduleupgrader\Plugin\DMU\Routing\ContentRoute->getController(Object(Drupal\drupalmoduleupgrader\Target), Object(Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper))
#13 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/src/Plugin/DMU/Routing/ContentRoute.php(163): Drupal\drupalmoduleupgrader\Plugin\DMU\Routing\ContentRoute->buildRouteDefinition(Object(Drupal\drupalmoduleupgrader\Target), Object(Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper))
#14 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/src/Plugin/DMU/Converter/Routing.php(75): Drupal\drupalmoduleupgrader\Plugin\DMU\Routing\ContentRoute->buildRoute(Object(Drupal\drupalmoduleupgrader\Target), Object(Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper))
#15 /Users/webchick/Sites/8.x/modules/drupalmoduleupgrader/drupalmoduleupgrader.drush.inc(336): Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Routing->convert(Object(Drupal\drupalmoduleupgrader\Target))
#16 [internal function]: drush_drupalmoduleupgrader_dmu_upgrade('pants')
#17 /Users/webchick/.composer/vendor/drush/drush/includes/command.inc(359): call_user_func_array('drush_drupalmod...', Array)
#18 /Users/webchick/.composer/vendor/drush/drush/includes/command.inc(210): _drush_invoke_hooks(Array, Array)
#19 [internal function]: drush_command('pants')
#20 /Users/webchick/.composer/vendor/drush/drush/includes/command.inc(178): call_user_func_array('drush_command', Array)
#21 /Users/webchick/.composer/vendor/drush/drush/lib/Drush/Boot/DrupalBoot.php(46): drush_dispatch(Array)
#22 /Users/webchick/.composer/vendor/drush/drush/drush.php(76): Drush\Boot\DrupalBoot->bootstrap_and_dispatch()
#23 /Users/webchick/.composer/vendor/drush/drush/drush.php(16): drush_main()
#24 {main}"
phenaproxima commented 9 years ago

I'm 99% sure I know what this, and it's not Pharborist's fault. Will explain in #drupal-contribute.

phenaproxima commented 9 years ago

Removing the won't fix label. The error could be better worded.

webchick commented 9 years ago

I believe #198 will fix this up.

grom358 commented 9 years ago

Merged.