Skip to content

Commit

Permalink
fix: Improve error reporting on incorrect entry (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jahredhope authored Dec 27, 2018
1 parent 5435303 commit 318413b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/createRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function evalutateFromSource(specifier, compilation) {
try {
source = getFileSourceFromCompilation(specifier, compilation);
} catch (error) {
throw new Error(`Error reading ${specifier}. Error: ${error}`);
throw new Error(`Error reading "${specifier}". Error: ${error}`);
}
return evaluate(
source,
Expand Down
17 changes: 8 additions & 9 deletions src/renderHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module.exports = async function renderHtml({
webpackStats
}) {
const renderFile = renderStats.assetsByChunkName[renderEntry];
trace("Render file:", { renderFile });
trace("Render route:", { renderFile });
if (!renderFile) {
throw new Error(
`Unable to find renderEntry ${renderEntry} in assets ${Object.keys(
`Unable to find renderEntry "${renderEntry}" in assets. Possible entries are: ${Object.keys(
renderStats.assetsByChunkName
)}.`
).join(", ")}.`
);
}

Expand All @@ -33,10 +33,9 @@ module.exports = async function renderHtml({
});
if (typeof renderFunc !== "function") {
throw new Error(
`Unable to find render function. File ${renderFile}. Recieved ${typeof renderFunc}.`
`Unable to find render function. File "${renderFile}". Recieved ${typeof renderFunc}.`
);
}
trace(`Renderer created`);

async function emitFile(dir, content) {
await new Promise((resolve, reject) =>
Expand Down Expand Up @@ -67,7 +66,7 @@ module.exports = async function renderHtml({
throw new Error(
`Missing route in ${JSON.stringify(
routeData
)}. Unable to render page without a path`
)}. Unable to render page without a route.`
);
}
const relativeFilePath = transformFilePath(routeData);
Expand All @@ -90,9 +89,9 @@ module.exports = async function renderHtml({
});
} catch (error) {
console.error(
`🚨 ${chalk.red("An error occured rending:")} ${chalk.blue(
`🚨 ${chalk.red(`An error occured rendering "`)} ${chalk.blue(
renderFile
)}. See below error.`
)}". See below error.`
);
console.error(error);
await emitFile(newFilePath, error.toString());
Expand All @@ -101,7 +100,7 @@ module.exports = async function renderHtml({

if (typeof renderResult !== "string") {
throw new Error(
`Render must return a string. Recieved ${typeof renderResult}.`
`Render must return a string. Recieved "${typeof renderResult}".`
);
}

Expand Down

0 comments on commit 318413b

Please sign in to comment.