{"record":{"id":"aeb58ce34919645e","repo":"FlowiseAI/Flowise","slug":"e","errorCode":null,"errorMessage":"${e}","messagePattern":"\\$\\{e\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts","lineNumber":214,"sourceCode":"\n            newState = processTemplateVariables(newState, finalOutput)\n\n            const returnOutput = {\n                id: nodeData.id,\n                name: this.name,\n                input: {\n                    inputVariables: functionInputVariables,\n                    code: javascriptFunction\n                },\n                output: {\n                    content: finalOutput\n                },\n                state: newState\n            }\n\n            return returnOutput\n        } catch (e) {\n            throw new Error(e)\n        }\n    }\n}\n\nmodule.exports = { nodeClass: CustomFunction_Agentflow }\n","sourceCodeStart":196,"sourceCodeEnd":220,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts#L196-L220","documentation":"CustomFunction.run executes user-supplied JavaScript in a sandbox via executeJavaScriptCode and wraps the whole run in try/catch. On any failure it does `throw new Error(e)`. Note: passing an Error object to `new Error(e)` stringifies it to 'Error: <msg>', losing the original stack and cause — a minor antipattern. The surfaced message is whatever the user's function threw or returned as an error.","triggerScenarios":"User code throws (ReferenceError, TypeError, syntax error), calls a non-existent variable, the sandbox blocks an operation, a referenced $inputVariable is undefined, axios call inside the function fails, or the function returns/throws a non-Error value.","commonSituations":"Typo in variable name inside the custom function; using a Node API not exposed in the sandbox; trying to import a library not in the allowed list (only 'axios' is passed); JSON.parse on undefined; async error not awaited.","solutions":["Open the Custom Function node and run the JavaScript standalone against the same inputs to reproduce.","Wrap risky sections in your own try/catch and return a defined value instead of throwing.","Use only sandbox-provided globals (input, $variable, flow, require('axios')); avoid process/fs/etc.","If you need a library, confirm it is in the allowed libraries list before using it.","Ensure async functions are awaited."],"exampleFix":"// before — throws on undefined parse\nfunction run() { return JSON.parse(input.missing) }\n\n// after — guard the input\nfunction run() {\n  const raw = input?.missing\n  return raw ? JSON.parse(raw) : null\n}","handlingStrategy":"try-catch","validationCode":"function lintUserFunction(src) {\n  // cheap pre-flight: syntax-check without executing\n  new Function('return async () => { ' + src + ' }')\n}\ntry { lintUserFunction(javascriptFunction) }\ncatch (e) { throw new Error('Custom function syntax error: ' + e.message) }","typeGuard":"function isAllowedSandboxKey(key) {\n  return ['input','flow','require','variables'].includes(key)\n}","tryCatchPattern":"try { await customFunctionNode.run(nodeData, input, options) }\ncatch (e) {\n  const m = e instanceof Error ? e.message : String(e)\n  // surface the function source line to the user; offer to open the editor\n  throw new Error('Custom function failed: ' + m)\n}","preventionTips":["Test custom functions in isolation with sample inputs before saving.","Only use sandbox-provided globals; do not rely on Node built-ins.","Wrap risky operations in try/catch inside the user function and return defined values.","Await all async operations."],"tags":["custom-function","sandbox","user-code","error-wrapping"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}