{"record":{"id":"823e4f652cf80069","repo":"n8n-io/n8n","slug":"syntax-error-error-message","errorCode":null,"errorMessage":"Syntax error: ${error.message}","messagePattern":"Syntax error: (.+?)","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/ast-interpreter/parser.ts","lineNumber":39,"sourceCode":"\ttry {\n\t\t// Acorn's AST is compatible with ESTree, but TypeScript doesn't know that\n\t\treturn acorn.parse(code, {\n\t\t\tecmaVersion: 'latest',\n\t\t\tsourceType: 'module',\n\t\t\tlocations: true, // Include line/column info for error messages\n\t\t}) as unknown as Program;\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError) {\n\t\t\t// Extract location from Acorn's error message\n\t\t\tconst match = (error as { loc?: { line: number; column: number } }).loc;\n\t\t\tconst location = match\n\t\t\t\t? {\n\t\t\t\t\t\tstart: { line: match.line, column: match.column },\n\t\t\t\t\t\tend: { line: match.line, column: match.column + 1 },\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\n\t\t\tthrow new InterpreterError(`Syntax error: ${error.message}`, location, code);\n\t\t}\n\t\tthrow error;\n\t}\n}\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/ast-interpreter/parser.ts#L21-L44","documentation":"Thrown by parseSDKCode (Acorn wrapper) when the input code fails to parse as valid JavaScript/ECMAScript. Acorn raises a SyntaxError; the wrapper extracts the location (line/column) from `error.loc` and re-throws as InterpreterError with a code frame. This is the top-level parse gate before any AST interpretation.","triggerScenarios":"Unclosed template literals, missing commas, unbalanced brackets/braces/parens, invalid token sequences, unterminated strings, stray characters. Any input string that is not syntactically valid ES (parsed with ecmaVersion 'latest', sourceType 'module').","commonSituations":"Hand-editing generated SDK code and leaving a syntax error; JSON.stringify double-escaping producing malformed code; copy-paste introducing smart quotes or missing closing braces; template literal `${}` with unbalanced backticks.","solutions":["Read the line/column in the error's code frame and fix the syntax at that exact location.","Paste the code into a JS/TS-aware editor (VS Code, ESLint) to locate the syntax error before submitting.","If the code was generated, regenerate it — do not hand-edit large generated blocks; if hand-editing, validate with a linter.","Check for unclosed template literals (backticks) and unbalanced brackets first — these are the most common cause flagged by the SDK error hint."],"exampleFix":"// before\nexport default workflow()\n  .add(node('X').parameters({ a: 1 )});\n\n// after\nexport default workflow()\n  .add(node('X').parameters({ a: 1 }));","handlingStrategy":"try-catch","validationCode":"// Validate syntax with a plain JS parser before feeding the SDK interpreter\nimport * as acorn from 'acorn';\n\nfunction checkSyntax(code: string): { ok: true } | { ok: false; message: string; line?: number } {\n  try {\n    acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', locations: true });\n    return { ok: true };\n  } catch (e) {\n    const err = e as { message: string; loc?: { line: number } };\n    return { ok: false, message: err.message, line: err.loc?.line };\n  }\n}","typeGuard":"function isParsableModule(code: string): boolean {\n  try {\n    acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module' });\n    return true;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"import { parseSDKCode } from '@n8n/workflow-sdk/ast-interpreter/parser';\nimport { InterpreterError } from '@n8n/workflow-sdk/ast-interpreter/errors';\n\ntry {\n  parseSDKCode(code);\n} catch (e) {\n  if (e instanceof InterpreterError && /Syntax error/.test(e.message)) {\n    // show the code frame + message to the user; the error carries line/column\n  }\n  throw e;\n}","preventionTips":["Always validate SDK code with acorn (or a JS-aware editor) before submitting it to the interpreter.","Bracket-balance: count '{', '}', '(', ')', '[', ']', '`' before submit.","Never hand-edit large generated code blocks; regenerate instead."],"tags":["sdk","parser","syntax-error","acorn"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}