FlowiseAI/Flowise · error · Error

${e}

Error message

${e}

What it means

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.

Source

Thrown at packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts:214

            newState = processTemplateVariables(newState, finalOutput)

            const returnOutput = {
                id: nodeData.id,
                name: this.name,
                input: {
                    inputVariables: functionInputVariables,
                    code: javascriptFunction
                },
                output: {
                    content: finalOutput
                },
                state: newState
            }

            return returnOutput
        } catch (e) {
            throw new Error(e)
        }
    }
}

module.exports = { nodeClass: CustomFunction_Agentflow }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Open the Custom Function node and run the JavaScript standalone against the same inputs to reproduce.
  2. Wrap risky sections in your own try/catch and return a defined value instead of throwing.
  3. Use only sandbox-provided globals (input, $variable, flow, require('axios')); avoid process/fs/etc.
  4. If you need a library, confirm it is in the allowed libraries list before using it.
  5. Ensure async functions are awaited.

Example fix

// before — throws on undefined parse
function run() { return JSON.parse(input.missing) }

// after — guard the input
function run() {
  const raw = input?.missing
  return raw ? JSON.parse(raw) : null
}
Defensive patterns

Strategy: try-catch

Validate before calling

function lintUserFunction(src) {
  // cheap pre-flight: syntax-check without executing
  new Function('return async () => { ' + src + ' }')
}
try { lintUserFunction(javascriptFunction) }
catch (e) { throw new Error('Custom function syntax error: ' + e.message) }

Type guard

function isAllowedSandboxKey(key) {
  return ['input','flow','require','variables'].includes(key)
}

Try / catch

try { await customFunctionNode.run(nodeData, input, options) }
catch (e) {
  const m = e instanceof Error ? e.message : String(e)
  // surface the function source line to the user; offer to open the editor
  throw new Error('Custom function failed: ' + m)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/aeb58ce34919645e. Report an issue: GitHub.