Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error raised with some chart types #778

Open
skye0402 opened this issue Nov 1, 2024 · 1 comment
Open

No error raised with some chart types #778

skye0402 opened this issue Nov 1, 2024 · 1 comment

Comments

@skye0402
Copy link

skye0402 commented Nov 1, 2024

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:

architecture-beta
    group user_group[User Interaction]
    service user[User 📱] in user_group
    service app[Mobile App 📲] in user_group

    group ai_group[AI Processing]
    service aihub[SAP BTP Generative AI Hub 🤖] in ai_group

    group s4hana_group[Backend]
    service s4hana[S/4HANA Product Master API 🛠️] in s4hana_group

    user:L -- R:app
    app:L -- R:aihub
    aihub:L -- R:app
    app:L -- R:s4hana

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
image

Desktop (please complete the following information):

  • OS: Linux Ubuntu latest version
  • Browser chromium
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@aloisklink
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants