From bf4272102daeb448732850e06359e4a0130e1384 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 11 Aug 2022 18:24:14 +0200 Subject: [PATCH] #3313 Packaging the thrown error in reconised structure --- cypress/platform/knsv2.html | 44 ++++++++----------------------------- src/mermaid.js | 32 +++++++++++++++------------ src/mermaidAPI.js | 2 +- 3 files changed, 28 insertions(+), 50 deletions(-) diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index f305ea2613..361c3bdc4d 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -41,7 +41,10 @@
Security check
-
+
+sequenceDiagram + Nothing:Valid; +
diff --git a/src/mermaid.js b/src/mermaid.js index a708554a8d..3d20922530 100644 --- a/src/mermaid.js +++ b/src/mermaid.js @@ -34,7 +34,7 @@ const init = function () { initThrowsErrors(...arguments); } catch (e) { log.warn('Syntax Error rendering'); - log.warn(e); + log.warn(e.str); if (this.parseError) { this.parseError(e); } @@ -120,19 +120,23 @@ const initThrowsErrors = function () { if (init) { log.debug('Detected early reinit: ', init); } - - mermaidAPI.render( - id, - txt, - (svgCode, bindFunctions) => { - element.innerHTML = svgCode; - if (typeof callback !== 'undefined') { - callback(id); - } - if (bindFunctions) bindFunctions(element); - }, - element - ); + try { + mermaidAPI.render( + id, + txt, + (svgCode, bindFunctions) => { + element.innerHTML = svgCode; + if (typeof callback !== 'undefined') { + callback(id); + } + if (bindFunctions) bindFunctions(element); + }, + element + ); + } catch (error) { + log.warn('Catching Error (bootstrap)'); + throw { error, message: error.str }; + } } }; diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index 5b16c609a4..6ab7f03b98 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -250,7 +250,7 @@ const render = function (id, _txt, cb, container) { txt = encodeEntities(txt); - // Imortant that we do not create the diagram until after the directives have been included + // Important that we do not create the diagram until after the directives have been included const diag = new Diagram(txt); // Get the tmp element containing the the svg const element = root.select('#d' + id).node();