From eb72c08e77e62caf5115c04467ad11a98a9fc5a5 Mon Sep 17 00:00:00 2001 From: Noel Forte Date: Tue, 4 Feb 2025 22:33:08 -0500 Subject: [PATCH 1/3] refactor `isPrematureTemplateContentError` with optional chaining --- src/Errors/EleventyErrorUtil.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Errors/EleventyErrorUtil.js b/src/Errors/EleventyErrorUtil.js index c87ea6a1b..a99ed1726 100644 --- a/src/Errors/EleventyErrorUtil.js +++ b/src/Errors/EleventyErrorUtil.js @@ -60,12 +60,11 @@ class EleventyErrorUtil { // TODO the rest of the template engines return ( e instanceof TemplateContentPrematureUseError || - (e.originalError && - (e.originalError.name === "RenderError" || - e.originalError.name === "UndefinedVariableError") && - e.originalError.originalError instanceof TemplateContentPrematureUseError) || // Liquid - (e.message || "").indexOf("TemplateContentPrematureUseError") > -1 - ); // Nunjucks + ((e?.originalError?.name === "RenderError" || + e?.originalError?.name === "UndefinedVariableError") && + e?.originalError?.originalError instanceof TemplateContentPrematureUseError) || // Liquid + e?.message?.includes("TemplateContentPrematureUseError") // Nunjucks + ); } } From 96e378c77c5f58879d844393746cca46161adf56 Mon Sep 17 00:00:00 2001 From: Noel Forte Date: Tue, 4 Feb 2025 22:38:14 -0500 Subject: [PATCH 2/3] remove extraneous tests on `originalError.name` e?.originalError?.originalError performs sufficient check for `TemplateContentPrematureUseError` --- src/Errors/EleventyErrorUtil.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Errors/EleventyErrorUtil.js b/src/Errors/EleventyErrorUtil.js index a99ed1726..518076b38 100644 --- a/src/Errors/EleventyErrorUtil.js +++ b/src/Errors/EleventyErrorUtil.js @@ -60,9 +60,7 @@ class EleventyErrorUtil { // TODO the rest of the template engines return ( e instanceof TemplateContentPrematureUseError || - ((e?.originalError?.name === "RenderError" || - e?.originalError?.name === "UndefinedVariableError") && - e?.originalError?.originalError instanceof TemplateContentPrematureUseError) || // Liquid + e?.originalError?.originalError instanceof TemplateContentPrematureUseError || // Liquid e?.message?.includes("TemplateContentPrematureUseError") // Nunjucks ); } From cdf3910f3b6c713810f8e8ebd17f3d62e67ab960 Mon Sep 17 00:00:00 2001 From: Noel Forte Date: Tue, 4 Feb 2025 22:43:44 -0500 Subject: [PATCH 3/3] add check for `TemplateContentPrematureUseError` in e?.cause in addition to other cases --- src/Errors/EleventyErrorUtil.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Errors/EleventyErrorUtil.js b/src/Errors/EleventyErrorUtil.js index 518076b38..d11076b2c 100644 --- a/src/Errors/EleventyErrorUtil.js +++ b/src/Errors/EleventyErrorUtil.js @@ -60,6 +60,7 @@ class EleventyErrorUtil { // TODO the rest of the template engines return ( e instanceof TemplateContentPrematureUseError || + e?.cause instanceof TemplateContentPrematureUseError || // Custom (per Node-convention) e?.originalError?.originalError instanceof TemplateContentPrematureUseError || // Liquid e?.message?.includes("TemplateContentPrematureUseError") // Nunjucks );