Skip to content

Commit

Permalink
Fixes #727
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 10, 2024
1 parent a2eed52 commit 1aa6c5d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ class Template extends TemplateContent {

getLayout(layoutKey) {
// already cached downstream in TemplateLayout -> TemplateCache
return TemplateLayout.getTemplate(layoutKey, this.eleventyConfig, this.extensionMap);
try {
return TemplateLayout.getTemplate(layoutKey, this.eleventyConfig, this.extensionMap);
} catch (e) {
throw new EleventyBaseError(
`Problem creating an Eleventy Layout for the "${this.inputPath}" template file.`,
e,
);
}
}

get baseFile() {
Expand Down
2 changes: 1 addition & 1 deletion src/TemplateWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class TemplateWriter {
},
(e) => {
this.errorHandler.error(e, "Error generating templates");
throw e;
return Promise.reject(e);
},
);
}
Expand Down
15 changes: 15 additions & 0 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,3 +1498,18 @@ test("Related to issue 3206: Does Nunjucks throwOnUndefined variables require no
t.is(results.length, 1);
t.is(results[0].content.trim(), `HELLO/:Custom Shortcode:/`);
});

test("#727: Error messaging when trying to use a missing layout", async (t) => {
let elev = new Eleventy("./test/stubs-virtual/", undefined, {
config: eleventyConfig => {
eleventyConfig.addTemplate("index.html", `HELLO {{ page.url }}`, {
layout: "does-not-exist.html",
});
}
});
elev.disableLogger();

await t.throwsAsync(() => elev.toJSON(), {
message: `Problem creating an Eleventy Layout for the "./test/stubs-virtual/index.html" template file.`
});
});

0 comments on commit 1aa6c5d

Please sign in to comment.