{"record":{"id":"2d43a030ff3d8b4b","repo":"iOfficeAI/OfficeCLI","slug":"mermaid-failed-to-render-extractmermaidmessage-d","errorCode":null,"errorMessage":"mermaid failed to render: {ExtractMermaidMessage(dom)}","messagePattern":"mermaid failed to render: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Diagram/MermaidImageRenderer.cs","lineNumber":377,"sourceCode":"        var htmlPath = Path.Combine(Path.GetTempPath(), $\"ocli_mmd_{Guid.NewGuid():N}.html\");\n        File.WriteAllText(htmlPath, html);\n        try\n        {\n            var dom = HtmlScreenshot.DumpDom(htmlPath)\n                ?? throw new InvalidOperationException(\"headless browser produced no output.\");\n\n            // The <title> is the AUTHORITATIVE outcome — not the presence of an <svg>.\n            // On a syntax error mermaid.parse() rejects (we capture the message) but\n            // STILL injects its red \"Syntax error\" bomb graphic into the DOM anyway\n            // (suppressErrorRendering doesn't stop it). So a viewBox is present even on\n            // failure; keying off the svg would screenshot the bomb and \"succeed\".\n            // Trust the title: MMDREADY = real render, MMDSYNTAX = bad input, else infra.\n            if (dom.Contains(\"<title>MMDSYNTAX</title>\", StringComparison.Ordinal))\n                throw new MermaidSyntaxException(\n                    \"mermaid syntax error: \" + ExtractMermaidMessage(dom)\n                    + \"\\n(fix the mermaid source, or use render=native for the built-in subset).\");\n            if (!dom.Contains(\"<title>MMDREADY</title>\", StringComparison.Ordinal))\n                throw new InvalidOperationException(\n                    dom.Contains(\"<title>MMDERR</title>\", StringComparison.Ordinal)\n                    ? \"mermaid failed to render: \" + ExtractMermaidMessage(dom)\n                    : \"mermaid produced no diagram (mermaid.js failed to load or the render timed out).\");\n\n            var (w, h) = ParseSvgSize(dom);\n            if (w <= 0 || h <= 0)\n                throw new InvalidOperationException(\"mermaid rendered but produced no measurable svg viewBox.\");\n\n            var pngPath = Path.ChangeExtension(htmlPath, \".png\");\n            if (!HtmlScreenshot.CaptureChromeSized(htmlPath, pngPath,\n                    (int)Math.Ceiling(w) + 2, (int)Math.Ceiling(h) + 2))\n                throw new InvalidOperationException(\"headless screenshot failed.\");\n            return pngPath;\n        }\n        finally { try { File.Delete(htmlPath); } catch { /* best effort */ } }\n    }\n\n    /// <summary>Cache → one-time download → live CDN. Returns a URL usable as a","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Diagram/MermaidImageRenderer.cs#L359-L395","documentation":"The DOM title was MMDSYNTAX's sibling failure marker MMDSYNTAX->no: specifically the title was MMDERR, meaning mermaid.js loaded and parsed but threw during render (a runtime error, not a syntax error). ExtractMermaidMessage returns the captured exception text. This is a renderer-level failure, not bad input.","triggerScenarios":"mermaid.parse() succeeded but mermaid.render() threw — e.g. a layout plugin (elk) failed to load, a theme frontmatter referenced a missing layout, an internal mermaid bug for a particular construct, or a diagram type needing an ESM-only module that didn't load.","commonSituations":"Source declares a layout (e.g. 'layout: elk') but the ELK layouter bundle failed to load in BuildHtmlEsm; a mermaid version regression that throws on specific shapes; theme frontmatter pointing at an unavailable theme.","solutions":["Read the MMDERR message text for the render-time exception.","If it names a layout plugin (elk), remove the layout frontmatter or ensure the ELK bundle loads (SourceNeedsElk path).","Strip theme/frontmatter to isolate whether the styled-ESM path is the cause.","Update or clear the cached mermaid.js so a different build is used, and retry."],"exampleFix":"// before — frontmatter forces ELK which fails to load\n---\nlayout: elk\n---\nflowchart TD\n  A --> B\n\n// after — default layout, renders without the plugin\nflowchart TD\n  A --> B","handlingStrategy":"try-catch","validationCode":"// If the source opts into a layout/theme, confirm the plugin path will load\nif (SourceNeedsElk(mermaid) && !ElkBundleAvailable())\n    throw new InvalidOperationException(\"ELK layout requested but the ELK bundle is unavailable.\");","typeGuard":null,"tryCatchPattern":"try { png = MermaidImageRenderer.RenderViaChrome(mermaid, bg); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"mermaid failed to render\", StringComparison.Ordinal))\n{\n    // retry without frontmatter, or fall back to native\n    png = MermaidImageRenderer.RenderViaChrome(StripFrontmatter(mermaid), bg);\n}","preventionTips":["Avoid 'layout: elk' unless the ELK bundle is confirmed to load.","Strip theme/layout frontmatter to isolate render failures.","Keep the cached mermaid.js at a stable version."],"tags":["mermaid","render","chrome","layout","elk","infrastructure"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}