{"record":{"id":"f760f2dd4406a2a6","repo":"n8n-io/n8n","slug":"cannot-call-non-function","errorCode":null,"errorMessage":"Cannot call non-function","messagePattern":"Cannot call non-function","errorType":"exception","errorClass":"InterpreterError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/ast-interpreter/interpreter.ts","lineNumber":296,"sourceCode":"\t\t\t\t\t\t`Allowed methods: ${allowedMethodNames().join(', ')}. ` +\n\t\t\t\t\t\t'Native array/string methods are not available in SDK code; ' +\n\t\t\t\t\t\t'use a Code node or an n8n expression for runtime logic.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (thisArg && typeof thisArg === 'object') {\n\t\t\t\tfunc = (thisArg as Record<string, unknown>)[methodName];\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new UnsupportedNodeError(\n\t\t\t\t`Callee type ${node.callee.type}`,\n\t\t\t\tnode.callee.loc ?? undefined,\n\t\t\t\tthis.sourceCode,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof func !== 'function') {\n\t\t\tthrow new InterpreterError(\n\t\t\t\t'Cannot call non-function',\n\t\t\t\tnode.loc ?? undefined,\n\t\t\t\tthis.sourceCode,\n\t\t\t);\n\t\t}\n\n\t\t// Evaluate arguments\n\t\tconst args = node.arguments.map((arg) => this.evaluate(arg));\n\n\t\t// Call the function\n\t\treturn func.apply(thisArg, args);\n\t}\n\n\t/**\n\t * Visit a member expression (for property access, not method calls).\n\t */\n\tprivate visitMemberExpression(node: ESTree.MemberExpression): unknown {\n\t\tvalidateMemberExpression(node, this.sourceCode);","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/ast-interpreter/interpreter.ts#L278-L314","documentation":"After resolving the callable value (from `sdkFunctions`, `variables`, or an object property), the interpreter checks `typeof func === 'function'` at interpreter.ts:295. If the resolved value isn't callable, it throws `InterpreterError`. This catches cases where you call a variable holding a non-function, or a property that doesn't exist on an object (resolves to `undefined`).","triggerScenarios":"Calling a variable that holds a non-function: `const x = 5; x()`. Or calling a property name that doesn't exist on a builder object: `obj.nonexistent()` resolves `func` to `undefined`, which fails the typeof check.","commonSituations":"Method name typo on an SDK builder; calling a variable that was assigned a literal value; accessing a property that resolves to undefined and then calling it.","solutions":["Verify the value is actually a function — check what the variable was assigned","Use only documented SDK method names on builder objects","Check for typos in method names against `allowedMethodNames()`"],"exampleFix":"// before\nconst config = { name: 'X' };\nconfig({ extra: true }); // config is an object, not a function\n\n// after\nconst wf = workflow({ name: 'X' });\nwf.add({ extra: true });","handlingStrategy":"type-guard","validationCode":"// Pre-check: verify that every call target resolves to a function\n// by tracing variable assignments in the SDK code","typeGuard":"// In the CALLER (TypeScript), after getting the interpreter result:\nfunction isFunction(value: unknown): value is Function {\n  return typeof value === 'function';\n}\n\n// In SDK code, guard with typeof before calling (typeof IS supported):\n// const fn = typeof x === 'function' ? x : null;\n// if (fn) { fn(); } — but note: if/call blocks are not available in SDK code.\n// Best: ensure the value is a function by construction.","tryCatchPattern":"import { InterpreterError } from '@n8n/workflow-sdk/ast-interpreter/errors';\n\ntry {\n  interpretSDKCode(sdkCode, sdkFunctions);\n} catch (e) {\n  if (e instanceof InterpreterError && e.message.includes('Cannot call non-function')) {\n    // verify method names against allowedMethodNames() and check variable assignments\n  }\n  throw e;\n}","preventionTips":["Only call documented SDK builder methods on objects","Verify that a variable holds a function before calling it (by checking its assignment)","Avoid calling properties that may not exist on builder objects"],"tags":["sdk-interpreter","type-error","runtime","non-function"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}