FlowiseAI/Flowise · error · Error

${e}

Error message

${e}

What it means

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.

Source

Thrown at packages/components/nodes/utilities/CustomFunction/CustomFunction.ts:147

        // Add input variables to sandbox
        if (Object.keys(inputVars).length) {
            for (const item in inputVars) {
                additionalSandbox[`$${item}`] = inputVars[item]
            }
        }

        const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)

        try {
            const response = await executeJavaScriptCode(javascriptFunction, sandbox)

            if (typeof response === 'string' && !isEndingNode) {
                return handleEscapeCharacters(response, false)
            }
            return response
        } catch (e) {
            throw new Error(e)
        }
    }

    async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
        return await this.init(nodeData, input, { ...options, isRun: true })
    }
}

module.exports = { nodeClass: CustomFunction_Utilities }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Run the function standalone in Node with the same inputs to reproduce and debug.
  2. Wrap risky sections inside the user function with try/catch and log details.
  3. Confirm all variables the function reads are present in the sandbox (input, variables, flow).
  4. If the failure is a timeout, optimize or simplify the function.

Example fix

// before (user function throws, library re-wraps losing stack)
// user code
function run(input) { return undefinedVar + 1 }

// after
function run(input) {
  if (typeof someVar === 'undefined') throw new Error('someVar missing in sandbox')
  return someVar + 1
}
// Library-side fix (avoid losing stack): throw e instanceof Error ? e : new Error(String(e))
Defensive patterns

Strategy: try-catch

Validate before calling

async function dryRunUserFn(fnSource: string, sandbox: Record<string, unknown>) {
  // surface syntax/runtime errors with full stack before the node runs
  try {
    const fn = new Function(...Object.keys(sandbox), fnSource)
    return await fn(...Object.values(sandbox))
  } catch (e) {
    throw new Error(`Custom function validation failed: ${(e as Error).message}`)
  }
}

Type guard

const isUserCodeError = (e: unknown): boolean =>
  e instanceof Error && !/JSON|URL|HTTP|Invalid/i.test(e.message)

Try / catch

try {
  return await customFunction.init(nodeData, input, options)
} catch (e) {
  const msg = (e as Error).message
  if (/is not defined|unexpected token|is not a function|cannot read prop/i.test(msg)) {
    throw new Error(`Bug in custom function: ${msg}`)
  }
  throw e
}

Prevention

When it happens

Trigger: The custom function references an undefined variable, throws explicitly, has a syntax error, hits an infinite loop/timeout, or calls a sandbox API incorrectly.

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

Related errors


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