elsa-workflows/elsa-core · error · InvalidOperationException

Target label ' ' not found in flowchart

Error message

Target label '{connNode.Target}' not found in flowchart

What it means

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.

Solutions

  1. Correct the target label to match an activity declared in the same flowchart.
  2. Declare the missing target activity with that label inside the flowchart.
  3. Delete or update connections that reference removed/renamed activities.
  4. Catch the exception and validate connection labels before compiling.

Example fix

// before
flowchart {
  a: Log("start");
  connect a -> finish; // 'finish' not defined
}
// after
flowchart {
  a: Log("start");
  finish: Log("done");
  connect a -> finish;
}
Defensive patterns

Strategy: validation

Validate before calling

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(', '));

Type guard

function targetsResolved(flowchart) { const labels = new Set(flowchart.activities.map(a => a.label)); return flowchart.connections.every(c => labels.has(c.target)); }

Try / catch

try { await compileScript(script); } catch (InvalidOperationException ex) when (ex.Message.StartsWith('Target label')) { highlightUnknownLabel(ex); }

Prevention

When it happens

Trigger: A FlowchartNode connection whose connNode.Target does not exist in the labelToActivity map built from the flowchart's declared activities.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/f3823229cf16079f. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Dsl.ElsaScript/Compiler/ElsaScriptCompiler.cs:388

        var labelToActivity = new Dictionary<string, IActivity>();
        foreach (var labeledNode in flowchart.Activities)
        {
            var activity = await CompileStatementAsync(labeledNode.Activity, cancellationToken);
            if (activity != null)
            {
                labelToActivity[labeledNode.Label] = activity;
            }
        }

        // Create connections
        var connections = new List<Connection>();
        foreach (var connNode in flowchart.Connections)
        {
            if (!labelToActivity.TryGetValue(connNode.Source, out var sourceActivity))
                throw new InvalidOperationException($"Source label '{connNode.Source}' not found in flowchart");

            if (!labelToActivity.TryGetValue(connNode.Target, out var targetActivity))
                throw new InvalidOperationException($"Target label '{connNode.Target}' not found in flowchart");

            var source = new Endpoint(sourceActivity, connNode.Outcome);
            var target = new Endpoint(targetActivity);
            connections.Add(new Connection(source, target));
        }

        // Create flowchart activity
        var flowchartActivity = new Workflows.Activities.Flowchart.Activities.Flowchart
        {
            Activities = labelToActivity.Values.ToList(),
            Connections = connections
        };

        // Set entry point if specified
        if (!string.IsNullOrEmpty(flowchart.EntryPoint))
        {
            if (!labelToActivity.TryGetValue(flowchart.EntryPoint, out var startActivity))
                throw new InvalidOperationException($"Entry point label '{flowchart.EntryPoint}' not found in flowchart");

View on GitHub (pinned to fe9217bdfa)