larowlan / vite-plugin-twig-drupal

Provides a vite plugin for rendering Drupal flavoured twig files with Storybook
MIT License
15 stars 4 forks source link

Add more error handling #1

Closed larowlan closed 8 months ago

larowlan commented 9 months ago

Steps to reproduce

Include a file with invalid syntax

Entry point:

{# file.twig #}
{% include "other-file.twig" %}

Invalid file:

{# other-file.twig #}
{% for foo in bar %}
{% endif %}

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error compiling twig file".] { code: 'ERR_UNHANDLED_REJECTION' }

Node.js v18.15.0

seanBlommaert commented 8 months ago

Just ran into this. I think it is the following code:

new Promise(async (resolve) => {
  const { includes, code } = await compileTemplate(
    template,
    file,
    options
  )
  includes.forEach(processIncludes)
  resolve(code)
})

Changing it to the following helped me find the issue in my twig template.

new Promise(async (resolve) => {
  const { includes, code } = await compileTemplate(
    template,
    file,
    options
  ).catch(errorHandler(id))
  if (includes) {
    includes.forEach(processIncludes)
  }
  resolve(code)
})
larowlan commented 8 months ago

Chance you could test #3 ?

github-actions[bot] commented 8 months ago

:tada: This issue has been resolved in version 1.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

seanBlommaert commented 8 months ago

Thanks, I'll test the new version, but looks good to me! I'll let you know if anything comes up.