Open skye0402 opened 3 weeks ago
I've replicated this issue.
It looks like Puppeteer is failing to throw the error somewhere, since the error from architecture diagrams is not JSON-ifiable, since it has circular dependencies.
The following seems to work-around it:
diff --git a/src/index.js b/src/index.js
index 3b14e8a..5d268b0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -264,7 +264,12 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
mermaid.registerLayoutLoaders(elkLayouts)
mermaid.initialize({ startOnLoad: false, ...mermaidConfig })
// should throw an error if mmd diagram is invalid
- const { svg: svgText } = await mermaid.render(svgId || 'my-svg', definition, container)
+ let svgText;
+ try {
+ ({ svg: svgText } = await mermaid.render(svgId || 'my-svg', definition, container))
+ } catch (error) {
+ throw new Error(error.message, {cause: error})
+ }
container.innerHTML = svgText
const svg = container.getElementsByTagName?.('svg')?.[0]
I might have a dig around the Mermaid source-code first, though, since I want to figure out why this Error has circular dependencies, since maybe we can fix the issue in the Mermaid project instead.
Describe the bug If a mermaid code contains an error the CLI should throw an error. However, for some cases like below there is no error thrown. Instead it creates an SVG with a bomb and the error remains unknown to the calling program giving it no possibility to correct the error.
To Reproduce
Use this diagram code:
Expected behavior The command line tool should raise an error when called with
mmdc -i error.mmd -o yest.svg -e svg -t dark -b transparent
Screenshots
Desktop (please complete the following information):
Additional context Add any other context about the problem here.