{"record":{"id":"135edfa9d22dfa77","repo":"iOfficeAI/OfficeCLI","slug":"diagram-has-no-nodes-the-mermaid-source-has-no-n","errorCode":null,"errorMessage":"diagram has no nodes — the mermaid source has no node/edge statements (e.g. 'flowchart TD; A[Start] --> B[End]').","messagePattern":"diagram has no nodes — the mermaid source has no node/edge statements \\(e\\.g\\. 'flowchart TD; A\\[Start\\] --> B\\[End\\]'\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Diagram/FlowchartLayout.cs","lineNumber":55,"sourceCode":"    {\n        public string From = \"\", To = \"\", Label = \"\";\n        public bool Rev, Self;\n        public List<string> Wp = new();     // waypoint dummy ids, source→target order\n        // routing scratch\n        public string SSide = \"\", TSide = \"\";\n        public Pt SRef, TRef;\n        public double LabelDy;\n    }\n\n    public static LaidOutGraph Layout(DiagramGraph g)\n    {\n        // A header with no node/edge statements (e.g. a bare \"flowchart TD\", or\n        // input whose only line failed to parse into a node) leaves zero nodes.\n        // Guard here with a clear message — otherwise the bounding-box Min/Max\n        // below throws a bare \"Sequence contains no elements\" that surfaces as\n        // internal_error. Mirrors SequenceLayout's empty-participants guard.\n        if (g.Nodes.Count == 0)\n            throw new ArgumentException(\n                \"diagram has no nodes — the mermaid source has no node/edge statements \"\n                + \"(e.g. 'flowchart TD; A[Start] --> B[End]').\");\n\n        bool td = g.Direction == FlowDirection.TopDown;\n        var nodes = new Dictionary<string, WNode>();\n        var real = new List<string>();\n        foreach (var dn in g.Nodes)\n        {\n            var n = new WNode { Id = dn.Id, Label = dn.Label, Shape = dn.Shape };\n            SizeNode(n);\n            nodes[dn.Id] = n;\n            real.Add(dn.Id);\n        }\n\n        var edges = new List<WEdge>();\n        foreach (var de in g.Edges)\n        {\n            if (!nodes.ContainsKey(de.From) || !nodes.ContainsKey(de.To)) continue;","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Diagram/FlowchartLayout.cs#L37-L73","documentation":"Thrown by FlowchartLayout.Layout (FlowchartLayout.cs:55) when the parsed DiagramGraph has zero nodes. This happens when the mermaid source has a flowchart header (or no header, defaulting to flowchart) but no parseable node/edge statements — e.g. a bare 'flowchart TD' with nothing after it, or a line that failed to parse into any node. The guard exists because otherwise the bounding-box Min/Max call later throws a bare 'Sequence contains no elements' that surfaces as an opaque internal_error.","triggerScenarios":"Compiling a source that is just 'flowchart TD' with no edges; a source whose only statement line is a comment (%%) or unparseable text; a sequence diagram that parsed zero participants would hit the analogous guard in SequenceLayout.","commonSituations":"Empty/incomplete mermaid pasted from a template; a flowchart whose body is all comments; node statements that use a syntax MermaidParser does not recognize so nothing is produced.","solutions":["Add at least one node or edge statement, e.g. 'flowchart TD; A[Start] --> B[End]'.","Remove leading %% comment-only lines that leave no real statements.","Verify the node syntax (A[Label], A-->B) matches what MermaidParser accepts."],"exampleFix":"// before\nflowchart TD\n// after\nflowchart TD\n  A[Start] --> B[End]","handlingStrategy":"validation","validationCode":"static void EnsureDiagramHasNodes(string mermaid)\n{\n    // crude pre-check: at least one line looks like a node or edge statement\n    var hasStatement = mermaid.Split('\\n')\n        .Select(l => l.Trim())\n        .Any(l => l.Length > 0 && !l.StartsWith(\"%%\") && !Regex.IsMatch(l, @\"^(flowchart|graph|sequenceDiagram)\b\", RegexOptions.IgnoreCase)\n            && (l.Contains(\"-->\") || l.Contains(\"---\") || Regex.IsMatch(l, @\"^\\w+[\\[\\(]\")));\n    if (!hasStatement) throw new ArgumentException(\"diagram has no node/edge statements\");\n}","typeGuard":"static bool DiagramLikelyHasNodes(string mermaid) =>\n    mermaid.Split('\\n').Select(l => l.Trim())\n        .Any(l => l.Length > 0 && !l.StartsWith(\"%%\") && (l.Contains(\"-->\") || l.Contains(\"---\") || Regex.IsMatch(l, @\"^\\w+[\\[\\(]\")));","tryCatchPattern":"try { FlowchartLayout.Layout(graph); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"diagram has no nodes\"))\n{ /* prompt user to add node/edge statements */ }","preventionTips":["Always include at least one edge (A-->B) or node statement (A[Label]) after the header.","Remove %%-only bodies that leave no real statements.","Validate the mermaid body is non-empty before compiling."],"tags":["diagram","mermaid","flowchart","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}