Fail Gracefully on Invalid YAML File Format

Created on 21 February 2021, almost 4 years ago
Updated 26 July 2023, over 1 year ago

Problem/Motivation

If I try importing a file that is not in YAML format it causes a fatal error, because the parseContent method of the ContentLoader class does not check whether the file contents were parsed correctly before trying to load them.

Steps to reproduce

  • Create a test file in the content directory with the correct naming, such as file1.content.yml, but instead of YAML syntax, put some other text in there such as PHP code.
  • Load the file via YAML Content drush command as usual.
  • See that there is a fatal error like
    Drupal\yaml_content\Event\ContentParsedEvent::__construct() must be of the type array, string given

Proposed resolution

Add logic to check if YAML parsing was successful. If not, display an error message and do not try to load the file.

Remaining tasks

User interface changes

API changes

Add logic to yaml_content/src/ContentLoader/ContentLoader.php, parseContent() method

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States anthonyf

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024