From 66a0bc3a11d28ddb33db511aba01c55221f1c735 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 20 Aug 2023 12:31:11 +0200 Subject: [PATCH] Extract error message/stack (#1619) --- mermaid/src/worker.js | 9 ++++++++- mermaid/test/convert-test.mjs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mermaid/src/worker.js b/mermaid/src/worker.js index 2e82fff3d..dc1ac2b19 100644 --- a/mermaid/src/worker.js +++ b/mermaid/src/worker.js @@ -74,7 +74,14 @@ export class Worker { const { svg } = await window.mermaid.render('container', definition) return { svg, error: null } } catch (err) { - return { svg: null, error: err } + return { + svg: null, + error: { + name: 'name' in err && err.name, + message: 'message' in err && err.message, + stack: 'stack' in err && err.stack + } + } } }, task.source, mermaidConfig) successfulSpan(span) diff --git a/mermaid/test/convert-test.mjs b/mermaid/test/convert-test.mjs index a8b5181a1..c97a30b2c 100644 --- a/mermaid/test/convert-test.mjs +++ b/mermaid/test/convert-test.mjs @@ -96,7 +96,7 @@ describe('#convert', function () { await new Worker(browser).convert(new Task('not a valid mermaid code', testCase.isPng)) expect.fail('Should throw a SyntaxError exception') } catch (err) { - expect(err.message).to.equal('Syntax error in graph: {"name":"UnknownDiagramError"}') + expect(err.message).to.be.a('string').and.satisfy(msg => msg.startsWith('Syntax error in graph: {"name":"UnknownDiagramError"'), 'Error message should starts with \'Syntax error in graph: {"name":"UnknownDiagramError\'') } finally { await browser.close() }