elsa-workflows/elsa-core · error · NotSupportedException

Statement type is not supported

Error message

Statement type {statement.GetType().Name} is not supported

What it means

ElsaScriptCompiler.CompileStatementAsync pattern-matches the AST statement against all supported node types (activity, for-each, for, while, switch, flowchart, listen, etc.); if a statement node falls through the switch, it throws NotSupportedException naming the node type. It means the script contains a construct the compiler does not know how to compile.

Solutions

  1. Upgrade Elsa.Dsl.ElsaScript to a version whose compiler supports the statement type reported in the message.
  2. Rewrite the script using supported statements (activity calls, var, if, for, foreach, while, switch, flowchart, listen).
  3. If you own the parser, add the missing case in CompileStatementAsync dispatching to a new Compile method.
  4. Catch NotSupportedException during compilation and surface the unsupported statement to the script author.

Example fix

// before
switch (statement) { ... } // no case for RepeatNode
// after (library-side)
RepeatNode repeatNode => await CompileRepeatAsync(repeatNode, cancellationToken),
_ => throw new NotSupportedException($"Statement type {statement.GetType().Name} is not supported");
Defensive patterns

Strategy: try-catch

Validate before calling

const supported = ['activity','if','foreach','for','while','switch','flowchart','listen']; if (!supported.includes(ast.node.type)) reportUnsupported(ast.node.type);

Type guard

function isSupportedStatement(node) { return node && supportedStatementTypes.has(node.type); }

Try / catch

try { result = await compiler.CompileAsync(script); } catch (NotSupportedException ex) { editor.showError('Unsupported statement: ' + ex.Message); }

Prevention

When it happens

Trigger: Compiling an ElsaScript whose AST contains a statement node type absent from the compiler's switch — typically after adding a new parser node type without adding a CompileXxx case, or using an unsupported statement in the script.

Common situations: A DSL language/version mismatch where the parser produces nodes the compiler predates, custom forked nodes, or using a newly documented statement with an older Elsa.Dsl.ElsaScript package.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

            return defaultValue;
        }
    }

    private async Task<IActivity?> CompileStatementAsync(StatementNode statement, CancellationToken cancellationToken = default)
    {
        return statement switch
        {
            VariableDeclarationNode varDecl => CompileVariableDeclaration(varDecl),
            ActivityInvocationNode actInv => await CompileActivityInvocationAsync(actInv, cancellationToken),
            BlockNode block => await CompileBlockAsync(block, cancellationToken),
            IfNode ifNode => await CompileIfAsync(ifNode, cancellationToken),
            ForEachNode forEach => await CompileForEachAsync(forEach, cancellationToken),
            ForNode forNode => await CompileForAsync(forNode, cancellationToken),
            WhileNode whileNode => await CompileWhileAsync(whileNode, cancellationToken),
            SwitchNode switchNode => await CompileSwitchAsync(switchNode, cancellationToken),
            FlowchartNode flowchart => await CompileFlowchartAsync(flowchart, cancellationToken),
            ListenNode listen => await CompileListenAsync(listen, cancellationToken),
            _ => throw new NotSupportedException($"Statement type {statement.GetType().Name} is not supported")
        };
    }

    private IActivity? CompileVariableDeclaration(VariableDeclarationNode varDecl)
    {
        // Create and register the variable
        var initialValue = varDecl.Value != null ? EvaluateConstantExpression(varDecl.Value) : null;
        var variable = new Variable(varDecl.Name, initialValue);
        _variables[varDecl.Name] = variable;

        // Variable declarations don't produce activities themselves
        return null;
    }

    private async Task<IActivity> CompileActivityInvocationAsync(ActivityInvocationNode actInv, CancellationToken cancellationToken = default)
    {
        // Try to find the activity type by name - try several strategies
        var activityDescriptor = await activityRegistryLookupService.FindAsync(actInv.ActivityName);

View on GitHub (pinned to fe9217bdfa)