Example with parse error: http://cgit.drupalcode.org/piwik/tree/piwik.info.yml?h=8.x-1.x&id=64b1b3...

The error:

11:49:05 WD php: Symfony\Component\Yaml\Exception\ParseException: Unexpected      [error]
11:49:05 characters near "s pages.'" in
11:49:05 "\/var\/tmp\/project_dependency_sourcecode_directory\/piwik\/piwik.info.yml"
11:49:05 at line 3 (near "description: 'Adds Piwik javascript tracking code to
11:49:05 all your site's pages.'"). in Symfony\Component\Yaml\Inline::parse()
11:49:05 (line 76 of
11:49:05 /var/www/drupal.org/htdocs/sites/all/vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php).
11:49:05 Symfony\Component\Yaml\Exception\ParseException: Unexpected characters near "s pages.'" in "\/var\/tmp\/project_dependency_sourcecode_directory\/piwik\/piwik.info.yml" at line 3 (near "description: 'Adds Piwik javascript tracking code to all your site's pages.'"). in Symfony\Component\Yaml\Inline::parse() (line 76 of /var/www/drupal.org/htdocs/sites/all/vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php).
11:49:05 Drush command terminated abnormally due to an unrecoverable error.       [error]
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drumm created an issue. See original summary.

trobey’s picture

Status: Active » Needs review

First, passing the filename to this function is now deprecated:

http://symfony.com/doc/current/components/yaml/introduction.html

So I have wrapped the filename with file_get_contents(). I have added a try-catch block and output any errors to watchdog. So here is the new code:

      try {
        $result = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
      } catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
        watchdog('project_dependency',
          'Unable to parse the YAML string:  %string',
          array('%string' => $e->getMessage())
        );
      }
      if (is_null($result)) {
        $info[$component] = $defaults;
      }
      else {
        $info[$component] = $result + $defaults;
      }

I hacked the code to test the Piwik example above. The $info array returned when the parsing error occurs is

Array
(
    [piwik] => Array
        (
            [name] => piwik
            [description] => 
            [dependencies] => Array
                (
                )

            [test_dependencies] => Array
                (
                )

            [title] => Unknown
        )

)

The dependencies returned are

Array
(
    [piwik] => Array
        (
        )

)

The watchdog error is

TYPE	project_dependency
DATE	Saturday, November 7, 2015 - 20:08
USER	Anonymous (not verified)
LOCATION	xxxxxxxxxxxxxxxxxxxxxxxxx
REFERRER	
MESSAGE	Unable to parse the YAML string: Unexpected characters near "s pages.'" at line 3 (near "description: 'Adds Piwik javascript tracking code to all your site's pages.'").
SEVERITY	notice
HOSTNAME	127.0.0.1
OPERATIONS	

Should I change the severity? Does this behavior make sense?

I will post a patch shortly.

trobey’s picture

  • trobey committed 057bb69 on 7.x-1.x
    Issue #2605590 by trobey: Handle Yaml parse errors gracefully
    
trobey’s picture

Status: Needs review » Fixed

I changed the severity level to error and committed it so it could be included in the next release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.