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
- Upgrade Elsa.Dsl.ElsaScript to a version whose compiler supports the statement type reported in the message.
- Rewrite the script using supported statements (activity calls, var, if, for, foreach, while, switch, flowchart, listen).
- If you own the parser, add the missing case in CompileStatementAsync dispatching to a new Compile method.
- 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
- Keep Elsa.Dsl.ElsaScript parser and compiler packages on the same version.
- Restrict script authoring UI to supported statement constructs.
- Pin package versions so a new parser node cannot reach an older compiler.
- Add compiler tests for every statement type you allow in scripts.
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
- Variable ' ' is not declared. Use 'var ' to declare a new…
- Variable ' ' is not declared. Use 'var ' to declare a new…
- Activity ' ' not found in registry
- Property ' ' not found on activity type
- Source label ' ' not found in flowchart
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)