{"record":{"id":"1df503688f022eb4","repo":"elsa-workflows/elsa-core","slug":"failed-to-parse-elsascript-errormessage","errorCode":null,"errorMessage":"Failed to parse ElsaScript: {errorMessage}","messagePattern":"Failed to parse ElsaScript: (.+?)","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Dsl.ElsaScript/Parser/ElsaScriptParser.cs","lineNumber":547,"sourceCode":"                        }\n                    }\n                };\n            });\n\n        var programParser = programWithWorkflow.Or(programWithStatements);\n\n        ProgramParser = programParser;\n    }\n\n    /// <inheritdoc />\n    public ProgramNode Parse(string source)\n    {\n        if (!ProgramParser.TryParse(source, out var result, out var error))\n        {\n            var errorMessage = error != null \n                ? $\"{error.Message} at {error.Position}\" \n                : \"Unknown parse error\";\n            throw new ParseException($\"Failed to parse ElsaScript: {errorMessage}\");\n        }\n        return result;\n    }\n\n    /// <summary>\n    /// Static helper to evaluate constant expressions during parsing.\n    /// </summary>\n    private static object EvaluateConstantExpressionStatic(ExpressionNode exprNode)\n    {\n        return exprNode switch\n        {\n            LiteralNode literal => literal.Value ?? string.Empty,\n            IdentifierNode identifier => identifier.Name,\n            _ => string.Empty\n        };\n    }\n}\n","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Dsl.ElsaScript/Parser/ElsaScriptParser.cs#L529-L565","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (missing colon after label)\nflowchart\n  Start WriteLine(\"hi\")\n// after\nflowchart\n  Start: WriteLine(\"hi\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var program = ElsaScriptParser.Parse(source); }\ncatch (ParseException ex)\n{\n    // ex.Message contains 'Failed to parse ElsaScript: <msg> at <position>'\n    var at = ex.Message.LastIndexOf(\" at \");\n    var pos = at >= 0 ? ex.Message[(at + 4)..] : \"unknown\";\n    logger.LogError(ex, \"ElsaScript syntax error near position {Pos}\", pos);\n    throw;\n}","preventionTips":["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"],"tags":["parser","syntax","elsascript"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}