{"record":{"id":"f3823229cf16079f","repo":"elsa-workflows/elsa-core","slug":"target-label-connnode-target-not-found-in-flowchart","errorCode":null,"errorMessage":"Target label '{connNode.Target}' not found in flowchart","messagePattern":"Target label '(.+?)' not found in flowchart","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Dsl.ElsaScript/Compiler/ElsaScriptCompiler.cs","lineNumber":388,"sourceCode":"        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))\n        {\n            if (!labelToActivity.TryGetValue(flowchart.EntryPoint, out var startActivity))\n                throw new InvalidOperationException($\"Entry point label '{flowchart.EntryPoint}' not found in flowchart\");","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Dsl.ElsaScript/Compiler/ElsaScriptCompiler.cs#L370-L406","documentation":"In the same connection-resolution loop, CompileFlowchartAsync looks up the connection's Target label; if it is not among the flowchart's activity labels, it throws InvalidOperationException naming the missing target label. Both endpoints of every connection must resolve to activities within the flowchart.","triggerScenarios":"A FlowchartNode connection whose connNode.Target does not exist in the labelToActivity map built from the flowchart's declared activities.","commonSituations":"Typo in the target label, dangling connections left after removing or renaming the target activity, or referencing an activity declared in a different flowchart/script scope.","solutions":["Correct the target label to match an activity declared in the same flowchart.","Declare the missing target activity with that label inside the flowchart.","Delete or update connections that reference removed/renamed activities.","Catch the exception and validate connection labels before compiling."],"exampleFix":"// before\nflowchart {\n  a: Log(\"start\");\n  connect a -> finish; // 'finish' not defined\n}\n// after\nflowchart {\n  a: Log(\"start\");\n  finish: Log(\"done\");\n  connect a -> finish;\n}","handlingStrategy":"validation","validationCode":"const labels = new Set(flowchart.activities.map(a => a.label)); const bad = flowchart.connections.filter(c => !labels.has(c.target)); if (bad.length) throw new Error('Unknown target labels: ' + bad.map(b => b.target).join(', '));","typeGuard":"function targetsResolved(flowchart) { const labels = new Set(flowchart.activities.map(a => a.label)); return flowchart.connections.every(c => labels.has(c.target)); }","tryCatchPattern":"try { await compileScript(script); } catch (InvalidOperationException ex) when (ex.Message.StartsWith('Target label')) { highlightUnknownLabel(ex); }","preventionTips":["Check both endpoints of every connection during pre-compile validation.","Clean up dangling connections when deleting target activities.","Use editor tooling that updates connections on activity rename."],"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"}