Skip to content

Commit 318413b

Browse files
authored
fix: Improve error reporting on incorrect entry (#14)
1 parent 5435303 commit 318413b

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/createRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function evalutateFromSource(specifier, compilation) {
1717
try {
1818
source = getFileSourceFromCompilation(specifier, compilation);
1919
} catch (error) {
20-
throw new Error(`Error reading ${specifier}. Error: ${error}`);
20+
throw new Error(`Error reading "${specifier}". Error: ${error}`);
2121
}
2222
return evaluate(
2323
source,

src/renderHtml.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ module.exports = async function renderHtml({
1818
webpackStats
1919
}) {
2020
const renderFile = renderStats.assetsByChunkName[renderEntry];
21-
trace("Render file:", { renderFile });
21+
trace("Render route:", { renderFile });
2222
if (!renderFile) {
2323
throw new Error(
24-
`Unable to find renderEntry ${renderEntry} in assets ${Object.keys(
24+
`Unable to find renderEntry "${renderEntry}" in assets. Possible entries are: ${Object.keys(
2525
renderStats.assetsByChunkName
26-
)}.`
26+
).join(", ")}.`
2727
);
2828
}
2929

@@ -33,10 +33,9 @@ module.exports = async function renderHtml({
3333
});
3434
if (typeof renderFunc !== "function") {
3535
throw new Error(
36-
`Unable to find render function. File ${renderFile}. Recieved ${typeof renderFunc}.`
36+
`Unable to find render function. File "${renderFile}". Recieved ${typeof renderFunc}.`
3737
);
3838
}
39-
trace(`Renderer created`);
4039

4140
async function emitFile(dir, content) {
4241
await new Promise((resolve, reject) =>
@@ -67,7 +66,7 @@ module.exports = async function renderHtml({
6766
throw new Error(
6867
`Missing route in ${JSON.stringify(
6968
routeData
70-
)}. Unable to render page without a path`
69+
)}. Unable to render page without a route.`
7170
);
7271
}
7372
const relativeFilePath = transformFilePath(routeData);
@@ -90,9 +89,9 @@ module.exports = async function renderHtml({
9089
});
9190
} catch (error) {
9291
console.error(
93-
`🚨 ${chalk.red("An error occured rending:")} ${chalk.blue(
92+
`🚨 ${chalk.red(`An error occured rendering "`)} ${chalk.blue(
9493
renderFile
95-
)}. See below error.`
94+
)}". See below error.`
9695
);
9796
console.error(error);
9897
await emitFile(newFilePath, error.toString());
@@ -101,7 +100,7 @@ module.exports = async function renderHtml({
101100

102101
if (typeof renderResult !== "string") {
103102
throw new Error(
104-
`Render must return a string. Recieved ${typeof renderResult}.`
103+
`Render must return a string. Recieved "${typeof renderResult}".`
105104
);
106105
}
107106

0 commit comments

Comments
 (0)