Skip to content

Commit

Permalink
Merge pull request #148 from CloudCannon/fix/hugo-error-boundary
Browse files Browse the repository at this point in the history
Fix/hugo error boundary
  • Loading branch information
bglw authored May 10, 2023
2 parents 7915f00 + 7211a74 commit b073b72
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion javascript-modules/engines/eleventy-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class Engine {
this.files[component_key] = [
`<div style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
`Failed to render ${deepest_errored_component[1]}. <br/>`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black;">`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black; white-space: pre-line;">`,
`<code style="font-family: monospace; color: black;">${error_string.replace(/</, '&lt;')}</code></pre>`,
`</div>`
].join('\n');
Expand Down
7 changes: 5 additions & 2 deletions javascript-modules/engines/hugo-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class Engine {
[deepest_errored_component]: [
`<div style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
`Failed to render ${deepest_errored_component}. <br/>`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black;">`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black; white-space: pre-line;">`,
`<code style="font-family: monospace; color: black;">${error_msg.replace(/</, '&lt;')}</code></pre>`,
`</div>`
].join('\n')
Expand All @@ -227,7 +227,10 @@ export class Engine {

const error_logs = log_messages.filter(log => log.startsWith("ERROR")).join("\n");
const missing_regex = /Component "([^"]+)" does not exist/ig;
file_stack = [...error_logs.matchAll(missing_regex)].map(([, file]) => `layouts/partials/bookshop/components/${file}/${file}.hugo.html`);
file_stack = [...error_logs.matchAll(missing_regex)].map(([, file]) => {
let filename = file.split('/').pop();
return `layouts/partials/bookshop/components/${file}/${filename}.hugo.html`;
});
if (file_stack.length) {
const deepest_errored_component = file_stack[file_stack.length-1];
window.writeHugoFiles(JSON.stringify({
Expand Down
2 changes: 1 addition & 1 deletion javascript-modules/engines/jekyll-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class Engine {
this.files[component_key] = [
`<div style="padding: 10px; background-color: lightcoral; color: black; font-weight: bold;">`,
`Failed to render ${deepest_errored_component[1]}. <br/>`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black;">`,
`<pre style="margin-top: 10px; background-color: lightcoral; border: solid 1px black; white-space: pre-line;">`,
`<code style="font-family: monospace; color: black;">${error_string.replace(/</, '&lt;')}</code></pre>`,
`</div>`
].join('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ Feature: Eleventy Bookshop CloudCannon Live Editing Error Boundaries
* 🌐 The selector h1:nth-of-type(2) should contain "Hello World 02"

Scenario: Bookshop replaces non-existent components in an error boundary
# Note: No `bad.eleventy.liquid` component has been created.
# Note: No `really/bad` component has been created.
Given 🌐 I have loaded my site in CloudCannon
When 🌐 CloudCannon pushes new yaml:
"""
components:
- _bookshop_name: good
text: Hello World 01
- _bookshop_name: bad
- _bookshop_name: really/bad
- _bookshop_name: good
text: Hello World 02
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ Feature: Hugo Bookshop CloudCannon Live Editing Error Boundaries
* 🌐 The selector h1:nth-of-type(2) should contain "Hello World 02"

Scenario: Bookshop replaces non-existent components in an error boundary
# Note: No `bad.hugo.html` component has been created.
# Note: No `really/bad` component has been created.
Given 🌐 I have loaded my site in CloudCannon
When 🌐 CloudCannon pushes new yaml:
"""
components:
- _bookshop_name: good
text: Hello World 01
- _bookshop_name: bad
- _bookshop_name: really/bad
- _bookshop_name: good
text: Hello World 02
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ Feature: Jekyll Bookshop CloudCannon Live Editing Error Boundaries
* 🌐 The selector h1:nth-of-type(2) should contain "Hello World 02"

Scenario: Bookshop replaces non-existent components in an error boundary
# Note: No `bad.jekyll.html` component has been created.
# Note: No `really/bad` component has been created.
Given 🌐 I have loaded my site in CloudCannon
When 🌐 CloudCannon pushes new yaml:
"""
components:
- _bookshop_name: good
text: Hello World 01
- _bookshop_name: bad
- _bookshop_name: really/bad
- _bookshop_name: good
text: Hello World 02
"""
Expand Down

0 comments on commit b073b72

Please sign in to comment.