{"record":{"id":"0b7b127cad3ccada","repo":"n8n-io/n8n","slug":"expression-evaluation-failed-errormessage","errorCode":null,"errorMessage":"Expression evaluation failed: ${errorMessage}","messagePattern":"Expression evaluation failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/bridge/isolated-vm-bridge.ts","lineNumber":798,"sourceCode":"\t\t\t// so TypeErrors from host callbacks should also go through the generic\n\t\t\t// wrapping for consistent behavior.\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t(error.name === 'ExpressionError' || error.name === 'ExpressionExtensionError')\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\tif (errorMessage.includes('Script execution timed out')) {\n\t\t\t\tthrow new TimeoutError(`Expression timed out after ${this.config.timeout}ms`, {});\n\t\t\t}\n\t\t\tif (errorMessage.includes('memory limit')) {\n\t\t\t\tthrow new MemoryLimitError(\n\t\t\t\t\t`Expression exceeded memory limit of ${this.config.memoryLimit}MB`,\n\t\t\t\t\t{},\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(`Expression evaluation failed: ${errorMessage}`);\n\t\t} finally {\n\t\t\tgetValueAtPath.release();\n\t\t\tgetArrayElement.release();\n\t\t\tcallHost.release();\n\t\t}\n\t}\n\n\t/**\n\t * Reconstruct an error from serialized isolate data.\n\t *\n\t * Maps error names back to their host-side classes and restores\n\t * custom properties that would otherwise be lost crossing the boundary.\n\t */\n\tprivate reconstructError(data: ErrorSentinel): Error {\n\t\tconst error = new Error(data.message);\n\t\terror.name = data.name || 'Error';\n\t\tif (data.stack) {\n\t\t\terror.stack = data.stack;","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/bridge/isolated-vm-bridge.ts#L780-L816","documentation":"Thrown as a generic Error('Expression evaluation failed: <errorMessage>') by IsolatedVmBridge.execute() when the isolate raised an error that is NOT an ExpressionError/ExpressionExtensionError, NOT a timeout, and NOT a memory-limit hit. It is the catch-all wrapper for everything else: unexpected runtime exceptions, uncaught TypeErrors from host callbacks (intentionally not special-cased), syntax issues that slipped past tournament, or isolate-internal failures. The original message is appended for diagnostics.","triggerScenarios":"Any isolate execution failure that doesn't match the timeout/memory/ExpressionError branches: a host callback throwing a non-Expression error, a ReferenceError inside the expression, a tournament-transformed code bug, or an isolate-internal fault. The wrapped errorMessage is the isolate's original text.","commonSituations":"A user expression referencing an undefined variable/method. A host callback (getValueAtPath/getArrayElement/callHost) throwing a non-Expression error due to unexpected data shape. A version skew between tournament transforms and the bridge. Debugging an expression that fails in an unclassified way.","solutions":["Read the appended errorMessage — it is the isolate's original error text and usually pinpoints the cause.","Reproduce the expression in isolation to see the underlying error class.","If a host callback is the source, ensure it throws ExpressionError/ExpressionExtensionError so it is re-thrown verbatim instead of wrapped.","Simplify the expression to the smallest reproducer to isolate the failing operation.","Check for undefined/null access on $json fields that the expression assumes exist."],"exampleFix":"// before — expression assumes a field exists; underlying ReferenceError gets wrapped\nconst result = evaluator.evaluate('{{ $json.contact.email.toUpperCase() }}', data, caller);\n// after — guard access; if it still fails, inspect the wrapped message\ntry {\n  const result = evaluator.evaluate('{{ $json.contact?.email?.toUpperCase() }}', data, caller);\n} catch (e) {\n  // e.message === 'Expression evaluation failed: Cannot read properties of undefined ...'\n  console.error(e.message);\n}","handlingStrategy":"try-catch","validationCode":"// No general pre-check covers all causes; narrow with targeted guards, e.g. null-safe access\nfunction toNullSafe(expr) { return expr.replace(/\\.(\\w+)/g, '?.$1'); } // conservative optional-chaining hint","typeGuard":"function isExpressionEvaluationFailure(e) {\n  return e instanceof Error && e.message.startsWith('Expression evaluation failed:');\n}","tryCatchPattern":"try {\n  const result = evaluator.evaluate(expr, data, caller);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Expression evaluation failed:')) {\n    // the appended text after the colon is the isolate's original error message\n    console.error('Underlying isolate error:', e.message.slice('Expression evaluation failed:'.length).trim());\n  } else throw e;\n}","preventionTips":["Use optional chaining (?.) in expressions to avoid Cannot-read-of-undefined errors.","If you build host callbacks, throw ExpressionError/ExpressionExtensionError so they are re-thrown verbatim instead of wrapped.","Reproduce the failing expression in isolation to read the underlying error class.","Simplify the expression to a minimal reproducer to locate the failing operation."],"tags":["expression-runtime","isolate","catch-all","runtime-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}