Skip to content

Commit

Permalink
Sander/guess error handling (#173)
Browse files Browse the repository at this point in the history
* improvement(treaverseapproutes): more explainatory error

update the error to list common casues, and exit the proccess

* improvement(contentrenderplugin.ts): better error on missin httpClienmodule or scully-content

* feat(contentrenderplugin): update other error display too

* fix(traverserouteplugin): fix wrong import
  • Loading branch information
SanderElias authored Jan 11, 2020
1 parent fac6eef commit cc63194
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 8 additions & 3 deletions scully/renderPlugins/contentRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export async function contentRenderPlugin(html: string, route: HandledRoute) {
const additionalHTML = await handleFile(extension, fileContent);
return insertContent(scullyBegin, scullyEnd, html, additionalHTML, getScript());
} catch (e) {
logError(`Error during content generation for ${yellow(file)}`, e);
logWarn(
`Error, probably missing "${yellow('<scully-conent>')}" or "${yellow('httpClientModule')}" for ${yellow(
file
)}`
);
}
}

Expand All @@ -28,9 +32,10 @@ function insertContent(startTag: string, endTag: string, html: string, insertTex
const [takeout, endText] = rest.split(endTag);
return [openingText, startTag, insertText, endTag, ...extras, endText].join('');
} catch (e) {}
logWarn(html);
logWarn(`missing "${yellow('<scully-conent>')}" or "${yellow('httpClientModule')}"`);
return `<h1>Scully could not find the &lt.scully-content&gt. tag in this page.</h1>
<p>Are you sure you inserted the mandatory "scully-content" in the component that is rendering this page?</p>
<p>This error can happen when you forgot to put the mandatory "scully-content" in the component that is rendering this page?</p>
<p>It may also occur if the 'httpClientModule' is not load in your app.module</p>
`;
}

Expand Down
10 changes: 9 additions & 1 deletion scully/routerPlugins/traverseAppRoutesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import {parseAngularRoutes} from 'guess-parser';
import {scullyConfig} from '../utils/config';
import {logError} from '../utils/log';

export const traverseAppRoutes = async (appRootFolder = scullyConfig.projectRoot) => {
try {
const routes = parseAngularRoutes(appRootFolder).map(r => r.path);

return routes;
} catch (e) {
console.log('e', e);
// console.log('e', e);
throw new Error('Scully could not traverse routes');
logError(`
We encountered a problem while reading the routes from your applications source.
This might happen when there are lazy-loaded routes, that are not loaded,
Or when there are paths we can not resolve statically.
Check the routes in your app, rebuild and retry.
`);
process.exit(15);
}
};

0 comments on commit cc63194

Please sign in to comment.