fix(EmailReadImap Node): Fix issue that crashed process if node was configured wrong (#3079)

* 🐛 Fix issue that IMAP node can crash n8n

* 👕 Fix lint issue
This commit is contained in:
Jan Oberhauser
2022-04-02 17:33:31 +02:00
committed by GitHub
parent 2c72584b55
commit 85f15d4989
5 changed files with 41 additions and 8 deletions

View File

@@ -1,13 +1,15 @@
import { ITriggerFunctions } from 'n8n-core';
import {
createDeferredPromise,
IBinaryData,
IBinaryKeyData,
IDataObject,
IDeferredPromise,
INodeExecutionData,
INodeType,
INodeTypeDescription,
ITriggerResponse,
LoggerProxy,
LoggerProxy as Logger,
NodeOperationError,
} from 'n8n-workflow';
@@ -25,10 +27,6 @@ import {
import * as lodash from 'lodash';
import {
LoggerProxy as Logger
} from 'n8n-workflow';
export class EmailReadImap implements INodeType {
description: INodeTypeDescription = {
displayName: 'EmailReadImap',
@@ -377,6 +375,8 @@ export class EmailReadImap implements INodeType {
return newEmails;
};
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise<void>();
const establishConnection = (): Promise<ImapSimple> => {
let searchCriteria = [
@@ -425,7 +425,11 @@ export class EmailReadImap implements INodeType {
}
} catch (error) {
Logger.error('Email Read Imap node encountered an error fetching new emails', { error });
throw error;
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
// if it receives an error before the workflow got activated
returnedPromise.promise().then(() => {
this.emitError(error as Error);
});
}
}
},
@@ -475,10 +479,12 @@ export class EmailReadImap implements INodeType {
await connection.end();
}
// Resolve returned-promise so that waiting errors can be emitted
returnedPromise.resolve();
return {
closeFunction,
};
}
}