{"record":{"id":"c11f33483d49581b","repo":"RocketChat/Rocket.Chat","slug":"error-running-script","errorCode":null,"errorMessage":"error-running-script","messagePattern":"error-running-script","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/integrations/lib/ScriptEngine.ts","lineNumber":367,"sourceCode":"\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\treturn wrapExceptions(() =>\n\t\t\tthis.runScriptMethod({\n\t\t\t\tintegrationId: integration._id,\n\t\t\t\tscript,\n\t\t\t\tmethod,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t).catch((err: any) => {\n\t\t\tthis.logger.error({\n\t\t\t\tmsg: 'Error running Script in Trigger',\n\t\t\t\tintegration: integration.name,\n\t\t\t\tscript: integration.scriptCompiled,\n\t\t\t\terr,\n\t\t\t});\n\t\t\tthrow new Error('error-running-script');\n\t\t});\n\t}\n\n\tprotected async hasScriptAndMethod(integration: IIntegration, method: keyof IScriptClass): Promise<boolean> {\n\t\tconst script = await this.getScriptSafely(integration);\n\t\treturn typeof script?.[method] === 'function';\n\t}\n\n\tprotected async getScriptSafely(integration: IIntegration): Promise<Partial<IScriptClass> | undefined> {\n\t\tif (this.disabled || integration.scriptEnabled !== true || !integration.scriptCompiled || integration.scriptCompiled.trim() === '') {\n\t\t\treturn;\n\t\t}\n\n\t\treturn wrapExceptions(() => this.getIntegrationScript(integration)).suppress();\n\t}\n\n\tprotected abstract isDisabled(): boolean;\n","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/integrations/lib/ScriptEngine.ts#L349-L385","documentation":"An outgoing integration's compiled script threw at runtime while a Trigger method (such as processOutgoingRequest) executed in the sandbox. ScriptEngine logs the real exception under 'Error running Script in Trigger' (with integration name and script) and rethrows this generic error to the caller.","triggerScenarios":"An integration with an enabled script whose method throws: TypeError on unexpected payload shapes, missing fields on the request/options data, or calls to undefined helpers during event processing or replay.","commonSituations":"Remote API response format changed and the script's parsing now fails; script written against a different integration data model; replay of old history whose payload shape differs.","solutions":["Check server logs for the preceding 'Error running Script in Trigger' entry — it contains the actual error and stack","Fix the script (null-checks, defensive parsing) and re-save the integration so it recompiles","Exercise the script in the integration editor's test/sandbox before re-enabling it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await triggerHandler.replay(integration, history);\n} catch (err) {\n  if (err instanceof Error && err.message === 'error-running-script') {\n    // script threw at runtime: check server logs for the real stack; fix the script, don't blind-retry\n    return;\n  }\n  throw err;\n}","preventionTips":["Wrap integration script bodies in their own try/catch and return structured error responses instead of throwing","Log the incoming request payload at the top of each script method","Re-test scripts whenever the integration's data sources change shape"],"tags":["integrations","scripting","apps","runtime-error"],"backgroundTag":"script-execution-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}