From 6eb47ad340d216c61ebffe386783553456fe648c Mon Sep 17 00:00:00 2001 From: syy11cn Date: Sun, 29 May 2022 19:20:56 +0800 Subject: [PATCH] feat(core): add error handler --- packages/core/src/cli.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/src/cli.ts b/packages/core/src/cli.ts index 96cdc9f..6f74bab 100644 --- a/packages/core/src/cli.ts +++ b/packages/core/src/cli.ts @@ -13,12 +13,19 @@ async function cli(props: { filename?: string theme?: string }): Promise { - console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: start...') + console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: Started...') const { filename = 'index.md' } = props - const file = readFileSync(`${cwd()}/${filename}`) - const buffer = await getBuffer({ markdown: file.toString(), config: defaultConfig }) - writeFileSync(`${cwd()}/My document.docx`, buffer) - console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: finish.') + try { + const file = readFileSync(`${cwd()}/${filename}`) + const buffer = await getBuffer({ markdown: file.toString(), config: defaultConfig }) + writeFileSync(`${cwd()}/My document.docx`, buffer) + } + catch (e) { + console.log(`[Markdown Report]: ${e}`) + console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: Failed.') + return + } + console.log('\x1B[36m%s\x1B[0m', '[Markdown Report]: Finished.') } cli({ filename: argv.md, theme: argv.theme })