Need to catch Peast exceptions

Created on 14 August 2023, over 1 year ago
Updated 30 August 2023, over 1 year ago

Problem/Motivation

We are having problems with Peast not being able to parse some of the JavaScripts generated by our theme build pipeline, causing aggregation to fail with a parsing exception (...and it's fairly slow for large files when it doesn't) in Drupal\Core\Asset\JsOptimizer.

Steps to reproduce

Aggregate any JS file which has a class with a method named `async`. See https://github.com/mck89/peast/issues/62 for a minimal example.
In our case, the file containing the class is generated by our theme building pipeline and part of the clientside runtime, so not something we can easily change.
An exception is thrown with just the parsing error message (no source file name or parsing position included) and the aggregation is aborted.

Note that if I hack around this and rename all the async methods in the file it parses correctly, but I would be hesitant to assume Peast won't choke on something else later - given build pipelines and JavaScript itself are constantly changing.

Proposed resolution

Wrap the calls to Peast in a try-catch and if the parsing or rendering fails, log the error and include the unprocessed file as before Peast was introduced.
If there was an actual JavaScript syntax error it would then be possible for a developer to more easily identify it as part of the aggregated file

Remaining tasks

Implement a fix.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.1

Component
Asset library 

Last updated about 7 hours ago

No maintainer
Created by

🇸🇪Sweden twod Sweden

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

Comments & Activities

Production build 0.71.5 2024