{"record":{"id":"39246dd0acceb722","repo":"elsa-workflows/elsa-core","slug":"source-label-connnode-source-not-found-in-flowchart","errorCode":null,"errorMessage":"Source label '{connNode.Source}' not found in flowchart","messagePattern":"Source label '(.+?)' not found in flowchart","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Dsl.ElsaScript/Compiler/ElsaScriptCompiler.cs","lineNumber":385,"sourceCode":"        }\n\n        // Compile all labeled activities and build a label-to-activity map\n        var labelToActivity = new Dictionary<string, IActivity>();\n        foreach (var labeledNode in flowchart.Activities)\n        {\n            var activity = await CompileStatementAsync(labeledNode.Activity, cancellationToken);\n            if (activity != null)\n            {\n                labelToActivity[labeledNode.Label] = activity;\n            }\n        }\n\n        // Create connections\n        var connections = new List<Connection>();\n        foreach (var connNode in flowchart.Connections)\n        {\n            if (!labelToActivity.TryGetValue(connNode.Source, out var sourceActivity))\n                throw new InvalidOperationException($\"Source label '{connNode.Source}' not found in flowchart\");\n\n            if (!labelToActivity.TryGetValue(connNode.Target, out var targetActivity))\n                throw new InvalidOperationException($\"Target label '{connNode.Target}' not found in flowchart\");\n\n            var source = new Endpoint(sourceActivity, connNode.Outcome);\n            var target = new Endpoint(targetActivity);\n            connections.Add(new Connection(source, target));\n        }\n\n        // Create flowchart activity\n        var flowchartActivity = new Workflows.Activities.Flowchart.Activities.Flowchart\n        {\n            Activities = labelToActivity.Values.ToList(),\n            Connections = connections\n        };\n\n        // Set entry point if specified\n        if (!string.IsNullOrEmpty(flowchart.EntryPoint))","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Dsl.ElsaScript/Compiler/ElsaScriptCompiler.cs#L367-L403","documentation":"CompileFlowchartAsync builds a label-to-activity map for the flowchart's activities, then resolves each connection's endpoints through that map; a connection whose Source label is missing throws InvalidOperationException. Every flowchart connection must reference a label defined by an activity in the same flowchart.","triggerScenarios":"A FlowchartNode whose Connections list contains a connection with connNode.Source not present in labelToActivity — i.e. the source label does not match any activity's label in the flowchart.","commonSituations":"Typo in the source label in the connection declaration, an activity removed/renamed while connections still reference the old label, or the activity with that label declared outside this flowchart block.","solutions":["Fix the connection's source label to exactly match a label of an activity in the flowchart.","Ensure each referenced activity is declared inside the flowchart block with the expected label.","Remove stale connections after renaming or deleting activities.","Catch the exception during compilation and flag the unknown label in the editor."],"exampleFix":"// before\nflowchart {\n  a: Log(\"start\");\n  connect a -> b; // no activity labeled 'b' yet\n}\n// after\nflowchart {\n  a: Log(\"start\");\n  b: Log(\"end\");\n  connect a -> b;\n}","handlingStrategy":"validation","validationCode":"const labels = new Set(flowchart.activities.map(a => a.label)); const bad = flowchart.connections.filter(c => !labels.has(c.source)); if (bad.length) throw new Error('Unknown source labels: ' + bad.map(b => b.source).join(', '));","typeGuard":"function sourcesResolved(flowchart) { const labels = new Set(flowchart.activities.map(a => a.label)); return flowchart.connections.every(c => labels.has(c.source)); }","tryCatchPattern":"try { await compileScript(script); } catch (InvalidOperationException ex) when (ex.Message.StartsWith('Source label')) { highlightUnknownLabel(ex); }","preventionTips":["Validate all connection labels against declared flowchart activities before compiling.","Regenerate/update connections whenever activities are renamed or removed.","Keep connections and activity declarations in the same flowchart block."],"tags":["dsl","flowchart","label-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}