Skip to content

Commit cc63194

Browse files
authored
Sander/guess error handling (#173)
* 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
1 parent fac6eef commit cc63194

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

scully/renderPlugins/contentRenderPlugin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export async function contentRenderPlugin(html: string, route: HandledRoute) {
1818
const additionalHTML = await handleFile(extension, fileContent);
1919
return insertContent(scullyBegin, scullyEnd, html, additionalHTML, getScript());
2020
} catch (e) {
21-
logError(`Error during content generation for ${yellow(file)}`, e);
21+
logWarn(
22+
`Error, probably missing "${yellow('<scully-conent>')}" or "${yellow('httpClientModule')}" for ${yellow(
23+
file
24+
)}`
25+
);
2226
}
2327
}
2428

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import {parseAngularRoutes} from 'guess-parser';
22
import {scullyConfig} from '../utils/config';
3+
import {logError} from '../utils/log';
34

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

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

0 commit comments

Comments
 (0)