diff --git a/packages/tools/website/build.ts b/packages/tools/website/build.ts index e33336c7df..a7e60e2b14 100644 --- a/packages/tools/website/build.ts +++ b/packages/tools/website/build.ts @@ -144,12 +144,17 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa } function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) { - let md = readFileSync(sourcePath, 'utf8'); - if (templateParams.isNews) { - md = processNewsMarkdown(md, sourcePath); + try { + let md = readFileSync(sourcePath, 'utf8'); + if (templateParams.isNews) { + md = processNewsMarkdown(md, sourcePath); + } + md = stripOffFrontMatter(md).doc; + return renderPageToHtml(md, targetPath, templateParams); + } catch (error) { + error.message = `Could not render file: ${sourcePath}: ${error.message}`; + throw error; } - md = stripOffFrontMatter(md).doc; - return renderPageToHtml(md, targetPath, templateParams); } function makeHomePageMd() { diff --git a/packages/tools/website/updateNews.ts b/packages/tools/website/updateNews.ts index dd8c87767d..65b70f733f 100644 --- a/packages/tools/website/updateNews.ts +++ b/packages/tools/website/updateNews.ts @@ -73,18 +73,23 @@ const getPosts = async (newsDir: string): Promise => { }; const getPostContent = async (post: Post): Promise => { - const raw = await readFile(post.path, 'utf8'); - const parsed = stripOffFrontMatter(raw); - const lines = parsed.doc.split('\n'); - const titleLine = lines[0]; - if (!titleLine.startsWith('# ')) throw new Error('Cannot extract title from post: no header detected'); - lines.splice(0, 1); + try { + const raw = await readFile(post.path, 'utf8'); + const parsed = stripOffFrontMatter(raw); + const lines = parsed.doc.split('\n'); + const titleLine = lines[0]; + if (!titleLine.startsWith('# ')) throw new Error('Cannot extract title from post: no header detected'); + lines.splice(0, 1); - return { - title: titleLine.substr(1).trim(), - body: lines.join('\n').trim(), - parsed, - }; + return { + title: titleLine.substr(1).trim(), + body: lines.join('\n').trim(), + parsed, + }; + } catch (error) { + error.message = `Could not get post content: ${post.id}: ${post.path}: ${error.message}`; + throw error; + } }; const execApi = async (method: HttpMethod, path: string, body: Record = null) => { diff --git a/packages/tools/website/utils/parser.ts b/packages/tools/website/utils/parser.ts index 6d1631c8fd..856d587e33 100644 --- a/packages/tools/website/utils/parser.ts +++ b/packages/tools/website/utils/parser.ts @@ -7,19 +7,24 @@ interface ReadmeDoc { } export async function readmeFileTitleAndBody(sourcePath: string): Promise { - let md = await readFile(sourcePath, 'utf8'); - md = stripOffFrontMatter(md).doc.trim(); - const r = md.match(/^# (.*)/); + try { + let md = await readFile(sourcePath, 'utf8'); + md = stripOffFrontMatter(md).doc.trim(); + const r = md.match(/^# (.*)/); - if (!r) { - throw new Error(`Could not determine title for Markdown file: ${sourcePath}`); - } else { - const lines = md.split('\n'); - lines.splice(0, 1); - return { - title: r[1], - body: lines.join('\n'), - }; + if (!r) { + throw new Error('Could not determine title'); + } else { + const lines = md.split('\n'); + lines.splice(0, 1); + return { + title: r[1], + body: lines.join('\n'), + }; + } + } catch (error) { + error.message = `On ${sourcePath}: ${error.message}`; + throw error; } }