mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Improve handling of incorrect return data of Function Nodes
This commit is contained in:
@@ -324,7 +324,7 @@ export default mixins(
|
||||
},
|
||||
jsonData (): IDataObject[] {
|
||||
const inputData = this.getNodeInputData(this.node, this.runIndex, this.outputIndex);
|
||||
if (inputData.length === 0) {
|
||||
if (inputData.length === 0 || !Array.isArray(inputData)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ export const nodeHelpers = mixins(
|
||||
|
||||
// Returns the data of the main input
|
||||
getMainInputData (connectionsData: ITaskDataConnections, outputIndex: number): INodeExecutionData[] {
|
||||
if (!connectionsData || !connectionsData.hasOwnProperty('main') || connectionsData.main === undefined || connectionsData.main.length < outputIndex) {
|
||||
if (!connectionsData || !connectionsData.hasOwnProperty('main') || connectionsData.main === undefined || connectionsData.main.length < outputIndex || connectionsData.main[outputIndex] === null) {
|
||||
return [];
|
||||
}
|
||||
return connectionsData.main[outputIndex] as INodeExecutionData[];
|
||||
|
||||
@@ -80,11 +80,36 @@ export class Function implements INodeType {
|
||||
|
||||
try {
|
||||
// Execute the function code
|
||||
items = await vm.run(`module.exports = async function() {${functionCode}}()`);
|
||||
items = (await vm.run(`module.exports = async function() {${functionCode}}()`));
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
|
||||
// Do very basic validation of the data
|
||||
if (items === undefined) {
|
||||
throw new Error('No data got returned. Always return an Array of items!');
|
||||
}
|
||||
if (!Array.isArray(items)) {
|
||||
throw new Error('Always an Array of items has to be returned!');
|
||||
}
|
||||
for (const item of items) {
|
||||
if (item.json === undefined) {
|
||||
throw new Error('All returned items have to contain property named "json"!');
|
||||
}
|
||||
if (item.json === undefined) {
|
||||
throw new Error('All returned items have to contain a property named "json"!');
|
||||
}
|
||||
if (typeof item.json !== 'object') {
|
||||
throw new Error('The json-property has to be an object!');
|
||||
}
|
||||
if (item.binary !== undefined) {
|
||||
if (Array.isArray(item.binary) || typeof item.binary !== 'object') {
|
||||
throw new Error('The binary-property has to be an object!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.prepareOutputData(items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,11 @@ export class FunctionItem implements INodeType {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
// Do very basic validation of the data
|
||||
if (jsonData === undefined) {
|
||||
throw new Error('No data got returned. Always an object has to be returned!');
|
||||
}
|
||||
|
||||
return {
|
||||
json: jsonData
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user