{"record":{"id":"9c8477cde2450015","repo":"FlowiseAI/Flowise","slug":"e-9c8477","errorCode":null,"errorMessage":"${e}","messagePattern":"\\$\\{e\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts","lineNumber":143,"sourceCode":"            if (output === 'document' && Array.isArray(response)) {\n                if (response.length === 0) return response\n                if (\n                    response[0].pageContent &&\n                    typeof response[0].pageContent === 'string' &&\n                    response[0].metadata &&\n                    typeof response[0].metadata === 'object'\n                )\n                    return response\n                throw new Error('Document object must contain pageContent and metadata')\n            }\n\n            if (output === 'text' && typeof response === 'string') {\n                return handleEscapeCharacters(response, false)\n            }\n\n            return response\n        } catch (e) {\n            throw new Error(e)\n        }\n    }\n}\n\nmodule.exports = { nodeClass: CustomDocumentLoader_DocumentLoaders }\n","sourceCodeStart":125,"sourceCodeEnd":149,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts#L125-L149","documentation":"Top-level catch around executeJavaScriptCode in CustomDocumentLoader. It re-wraps any thrown value as new Error(e). If e is an Error, new Error(errorObject) calls errorObject.toString() so the original stack and name (SyntaxError, ReferenceError, etc.) are flattened into a generic Error message. This also re-wraps the [110] contract error, masking which check failed.","triggerScenarios":"Sandbox function threw a ReferenceError (undefined variable), SyntaxError (bad JS), TypeError, or timed out; the contract check at [110] threw and was re-caught here.","commonSituations":"User code has a typo or references an undefined sandbox variable; the function references a library not in the allowed list (['axios']); an exception from the document-shape check gets flattened so the user sees only 'Error: ...'.","solutions":["Read the message text carefully - it usually contains the underlying error string even though the type is lost.","If the message matches 'Document object must contain pageContent and metadata', the root cause is the shape contract (see error 110).","Wrap your sandbox body in its own try/catch and throw a descriptive Error so the outer wrapper has something useful to re-wrap.","Run the function body in Node with the same inputs to reproduce the underlying exception with its real stack."],"exampleFix":"// before\n} catch (e) {\n  throw new Error(e)\n}\n// after - preserve the original error chain\n} catch (e) {\n  if (e instanceof Error) throw e\n  throw new Error(typeof e === 'string' ? e : JSON.stringify(e))\n}","handlingStrategy":"try-catch","validationCode":"function validateSandboxSource(fn: string): void {\n  if (typeof fn !== 'string' || fn.trim() === '') throw new Error('javascriptFunction input is empty')\n  // basic balance check to catch SyntaxError early\n  const open = (fn.match(/[({[]/g) || []).length\n  const close = (fn.match(/[)}\\]]/g) || []).length\n  if (open !== close) throw new Error(`javascriptFunction has unbalanced brackets: ${open} open vs ${close} close`)\n}\n// validateSandboxSource(nodeData.inputs?.javascriptFunction) before executeJavaScriptCode","typeGuard":"function isErrorWithMessage(e: unknown): e is Error {\n  return e instanceof Error || (typeof e === 'object' && e !== null && 'message' in e)\n}","tryCatchPattern":"try {\n  const result = await executeJavaScriptCode(javascriptFunction, sandbox, { libraries: ['axios'] })\n  return result\n} catch (e) {\n  // The outer wrapper flattens e to a string message; parse it back\n  const msg = e instanceof Error ? e.message : String(e)\n  if (/is not defined/.test(msg)) throw new Error(`Sandbox ReferenceError: ${msg}. Allowed vars: input, $<inputVars>, flow, vars.`)\n  throw e\n}","preventionTips":["Only reference sandbox-allowed variables (input, flow, vars, $<inputVar>).","Only import libraries explicitly allowed (['axios']); others will throw.","Validate your function in plain Node with the same inputs first."],"tags":["error-handling","javascript","sandbox","custom-document-loader"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}