Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Error.cause for TemplateContentPrematureUseError when rendering #3651

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

noelforte
Copy link
Contributor

This PR may address the issue of #2328, and resolves a downstream issue in noelforte/eleventy-plugin-vento#120.

I've patched the static method EleventyErrorUtil.isPrematureTemplateContentError to search for instances of TemplateContentPrematureUseErrors within Error.cause as well, so rethrown errors (from a Custom Template Language in my case) are properly caught by Eleventy.

As work on #3582 continues, the implementation here could probably be cleaned up even more but I figured I'd start with this single patch.

I've also added additional changes in separate commits for the following:

  1. Refactored the conditional to leverage optional chaining (?.)
  2. Removed extra checks on originalError.name that didn't seem to have any effect since originalError.originalError is what we're actually looking to identify. Unless of course TemplateContentPrematureUseErrors can be thrown in cases that are not RenderErrors or UndefinedVariableErrors, in which case you can drop that commit.

Let me know if there's any changes!

e?.originalError?.originalError performs sufficient check for `TemplateContentPrematureUseError`
in e?.cause in addition to other cases
@noelforte noelforte requested a review from zachleat as a code owner February 5, 2025 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant