Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export const addIncomingIntegration = async (userId: string, integration: INewIn
} catch (e) {
integrationData.scriptCompiled = undefined;
integrationData.scriptError = e instanceof Error ? _.pick(e, 'name', 'message', 'stack') : undefined;

// Surfacing the error to the UI to prevent saving a broken integration
throw new Meteor.Error(
'error-invalid-script',
`Compilation Error: ${e instanceof Error ? e.message : 'Unknown error'}`,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,48 +82,52 @@ export const updateIncomingIntegration = async (
});
}

const isFrozen = isScriptEngineFrozen(scriptEngine);

if (!isFrozen) {
let scriptCompiled: string | undefined;
let scriptError: Pick<Error, 'name' | 'message' | 'stack'> | undefined;

if (integration.scriptEnabled === true && integration.script && integration.script.trim() !== '') {
try {
let babelOptions = Babel.getDefaultOptions({ runtime: false });
babelOptions = _.extend(babelOptions, { compact: true, minified: true, comments: false });

scriptCompiled = Babel.compile(integration.script, babelOptions).code;
scriptError = undefined;
await Integrations.updateOne(
{ _id: integrationId },
{
$set: {
scriptCompiled,
},
$unset: { scriptError: 1 as const },
},
);
} catch (e) {
scriptCompiled = undefined;
if (e instanceof Error) {
const { name, message, stack } = e;
scriptError = { name, message, stack };
}
await Integrations.updateOne(
{ _id: integrationId },
{
$set: {
scriptError,
},
$unset: {
scriptCompiled: 1 as const,
},
},
);
const isFrozen = isScriptEngineFrozen(scriptEngine);

if (!isFrozen) {
let scriptCompiled: string | undefined;
let scriptError: Pick<Error, 'name' | 'message' | 'stack'> | undefined;

if (integration.scriptEnabled === true && integration.script && integration.script.trim() !== '') {
try {
let babelOptions = Babel.getDefaultOptions({ runtime: false });
babelOptions = _.extend(babelOptions, { compact: true, minified: true, comments: false });

scriptCompiled = Babel.compile(integration.script, babelOptions).code;
scriptError = undefined;

await Integrations.updateOne(
{ _id: integrationId },
{
$set: { scriptCompiled },
$unset: { scriptError: 1 as const },
},
);
} catch (e) {
scriptCompiled = undefined;
if (e instanceof Error) {
const { name, message, stack } = e;
scriptError = { name, message, stack };
}

await Integrations.updateOne(
{ _id: integrationId },
{
$set: { scriptError },
$unset: { scriptCompiled: 1 as const },
},
);

// This prevents the "silent failure" and notifies the user
throw new Meteor.Error('error-invalid-script', `Compilation Error: ${e instanceof Error ? e.message : 'Unknown error'}`);
}
}
}

// The loop MUST stay outside the script processing logic
for await (let channel of channels) {
// ... channel validation logic ...
}

for await (let channel of channels) {
const channelType = channel[0];
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"Firefox ESR"
],
"dependencies": {
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
"@babel/runtime": "~7.28.4",
"@bugsnag/js": "~7.20.2",
"@bugsnag/plugin-react": "~7.19.0",
Expand Down