From 9e4611fb3172e84063c007ce247e775d1d937ecf Mon Sep 17 00:00:00 2001 From: kamiazya Date: Mon, 30 Nov 2020 23:06:32 +0900 Subject: [PATCH] feat(rediagram): add error handling on runnning code #133 --- packages/rediagram/src/formats.ts | 48 +++++++++++++++++++------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/rediagram/src/formats.ts b/packages/rediagram/src/formats.ts index b510648f..861efcc3 100644 --- a/packages/rediagram/src/formats.ts +++ b/packages/rediagram/src/formats.ts @@ -31,12 +31,16 @@ export async function PNG( element: ReactElement, { name, dir, _caller = caller() }: InternalRenderOption = {}, ): Promise { - const p = path.parse(_caller); - await Rediagram.render(element, { - format: 'png', - name: name ?? p.name, - dir: dir ?? Rediagram.config.output.dir ?? p.dir, - }); + try { + const p = path.parse(_caller); + await Rediagram.render(element, { + format: 'png', + name: name ?? p.name, + dir: dir ?? Rediagram.config.output.dir ?? p.dir, + }); + } catch (err) { + Rediagram.logger.error(err); + } } /** @@ -47,12 +51,16 @@ export async function SVG( element: ReactElement, { name, dir, _caller = caller() }: InternalRenderOption = {}, ): Promise { - const p = path.parse(_caller); - await Rediagram.render(element, { - format: 'svg', - name: name ?? p.name, - dir: dir ?? Rediagram.config.output.dir ?? p.dir, - }); + try { + const p = path.parse(_caller); + await Rediagram.render(element, { + format: 'svg', + name: name ?? p.name, + dir: dir ?? Rediagram.config.output.dir ?? p.dir, + }); + } catch (err) { + Rediagram.logger.error(err); + } } /** @@ -63,10 +71,14 @@ export async function PDF( element: ReactElement, { name, dir, _caller = caller() }: InternalRenderOption = {}, ): Promise { - const p = path.parse(_caller); - await Rediagram.render(element, { - format: 'pdf', - name: name ?? p.name, - dir: dir ?? Rediagram.config.output.dir ?? p.dir, - }); + try { + const p = path.parse(_caller); + await Rediagram.render(element, { + format: 'pdf', + name: name ?? p.name, + dir: dir ?? Rediagram.config.output.dir ?? p.dir, + }); + } catch (err) { + Rediagram.logger.error(err); + } }