elsa-workflows/elsa-core · error · ParseException
Failed to parse ElsaScript
Error message
Failed to parse ElsaScript: {errorMessage} What it means
ElsaScriptParser wraps all parse failures from ProgramParser.TryParse in a single ParseException whose message includes the underlying error and character position. It is the top-level parse gate: any syntax error in an ElsaScript source surfaces this way, with the root cause embedded in the message text.
Solutions
- Read the embedded '{error.Message} at {position}' portion and fix the syntax at that exact character position
- Validate braces, parentheses, and statement separators around the reported position
- Compare the failing syntax with a known-good ElsaScript example of the same construct
- Parse incrementally: comment out blocks and re-parse to isolate the offending region
Example fix
// before (missing colon after label)
flowchart
Start WriteLine("hi")
// after
flowchart
Start: WriteLine("hi") Defensive patterns
Strategy: try-catch
Try / catch
try { var program = ElsaScriptParser.Parse(source); }
catch (ParseException ex)
{
// ex.Message contains 'Failed to parse ElsaScript: <msg> at <position>'
var at = ex.Message.LastIndexOf(" at ");
var pos = at >= 0 ? ex.Message[(at + 4)..] : "unknown";
logger.LogError(ex, "ElsaScript syntax error near position {Pos}", pos);
throw;
} Prevention
- Keep an ElsaScript syntax reference/snippets handy while editing
- Use an editor plugin or formatter for ElsaScript to catch syntax early
- Parse scripts in CI as a smoke test before deployment
- Isolate changes incrementally when a large script fails to parse
When it happens
Trigger: Calling the parser (e.g. via ElsaScriptCompiler or the ElsaScript language provider) with source that violates ElsaScript grammar — unbalanced braces, missing separators, invalid activity syntax, stray characters — at any position reported in the message.
Common situations: Hand-editing workflow scripts and introducing typos; paste from docs with mismatched syntax versions; generating scripts programmatically with malformed output; wrong quoting/escaping in string literals.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Entry point label ' ' not found in flowchart
- Expression type is not supported
- Expression type is not supported as Expression
- Multiple matching constructors found for activity type
- No matching constructor found for activity type
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/1df503688f022eb4.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Dsl.ElsaScript/Parser/ElsaScriptParser.cs:547
}
}
};
});
var programParser = programWithWorkflow.Or(programWithStatements);
ProgramParser = programParser;
}
/// <inheritdoc />
public ProgramNode Parse(string source)
{
if (!ProgramParser.TryParse(source, out var result, out var error))
{
var errorMessage = error != null
? $"{error.Message} at {error.Position}"
: "Unknown parse error";
throw new ParseException($"Failed to parse ElsaScript: {errorMessage}");
}
return result;
}
/// <summary>
/// Static helper to evaluate constant expressions during parsing.
/// </summary>
private static object EvaluateConstantExpressionStatic(ExpressionNode exprNode)
{
return exprNode switch
{
LiteralNode literal => literal.Value ?? string.Empty,
IdentifierNode identifier => identifier.Name,
_ => string.Empty
};
}
}
View on GitHub (pinned to fe9217bdfa)