{"record":{"id":"6b94edbe28ccde10","repo":"FlowiseAI/Flowise","slug":"e-6b94ed","errorCode":null,"errorMessage":"${e}","messagePattern":"\\$\\{e\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/utilities/CustomFunction/CustomFunction.ts","lineNumber":147,"sourceCode":"\n        // Add input variables to sandbox\n        if (Object.keys(inputVars).length) {\n            for (const item in inputVars) {\n                additionalSandbox[`$${item}`] = inputVars[item]\n            }\n        }\n\n        const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)\n\n        try {\n            const response = await executeJavaScriptCode(javascriptFunction, sandbox)\n\n            if (typeof response === 'string' && !isEndingNode) {\n                return handleEscapeCharacters(response, false)\n            }\n            return response\n        } catch (e) {\n            throw new Error(e)\n        }\n    }\n\n    async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {\n        return await this.init(nodeData, input, { ...options, isRun: true })\n    }\n}\n\nmodule.exports = { nodeClass: CustomFunction_Utilities }\n","sourceCodeStart":129,"sourceCodeEnd":157,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts#L129-L157","documentation":"Thrown by CustomFunction_Utilities.init as the catch-all around executeJavaScriptCode, which runs the user-supplied `javascriptFunction` in a sandbox. The user code raised an exception (syntax error, runtime error, reference error, timeout). Note `throw new Error(e)` coerces `e` to a string, losing the original stack trace and any custom error class — a known code smell.","triggerScenarios":"The custom function references an undefined variable, throws explicitly, has a syntax error, hits an infinite loop/timeout, or calls a sandbox API incorrectly.","commonSituations":"User-authored JS has a typo or references a variable not in the sandbox; the function assumes globals that are restricted; logic bug throws at runtime; copy-paste left a syntax error.","solutions":["Run the function standalone in Node with the same inputs to reproduce and debug.","Wrap risky sections inside the user function with try/catch and log details.","Confirm all variables the function reads are present in the sandbox (input, variables, flow).","If the failure is a timeout, optimize or simplify the function."],"exampleFix":"// before (user function throws, library re-wraps losing stack)\n// user code\nfunction run(input) { return undefinedVar + 1 }\n\n// after\nfunction run(input) {\n  if (typeof someVar === 'undefined') throw new Error('someVar missing in sandbox')\n  return someVar + 1\n}\n// Library-side fix (avoid losing stack): throw e instanceof Error ? e : new Error(String(e))","handlingStrategy":"try-catch","validationCode":"async function dryRunUserFn(fnSource: string, sandbox: Record<string, unknown>) {\n  // surface syntax/runtime errors with full stack before the node runs\n  try {\n    const fn = new Function(...Object.keys(sandbox), fnSource)\n    return await fn(...Object.values(sandbox))\n  } catch (e) {\n    throw new Error(`Custom function validation failed: ${(e as Error).message}`)\n  }\n}","typeGuard":"const isUserCodeError = (e: unknown): boolean =>\n  e instanceof Error && !/JSON|URL|HTTP|Invalid/i.test(e.message)","tryCatchPattern":"try {\n  return await customFunction.init(nodeData, input, options)\n} catch (e) {\n  const msg = (e as Error).message\n  if (/is not defined|unexpected token|is not a function|cannot read prop/i.test(msg)) {\n    throw new Error(`Bug in custom function: ${msg}`)\n  }\n  throw e\n}","preventionTips":["Unit-test user functions standalone with representative sandbox inputs before deploying.","List all sandbox variables the function reads and assert they exist before execution.","Wrap risky sections inside the user function with try/catch and log specifics.","Prefer pure functions over reaching into globals."],"tags":["javascript","sandbox","user-code","custom-function","error-wrapping"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}