mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Read Binary File Node): Do not crash the execution when the source file does not exist (#5100)
This issue was introduced in https://github.com/n8n-io/n8n/pull/5069
This commit is contained in:
committed by
GitHub
parent
c4df2049a8
commit
c97f3cad59
@@ -1,12 +1,5 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { createReadStream } from 'fs';
|
||||
import type { IExecuteFunctions } from 'n8n-core';
|
||||
import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
||||
|
||||
export class ReadBinaryFile implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -53,23 +46,6 @@ export class ReadBinaryFile implements INodeType {
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
try {
|
||||
item = items[itemIndex];
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
|
||||
const filePath = this.getNodeParameter('filePath', itemIndex) as string;
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = createReadStream(filePath);
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`The file "${filePath}" could not be found.`,
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: item.json,
|
||||
binary: {},
|
||||
@@ -85,7 +61,10 @@ export class ReadBinaryFile implements INodeType {
|
||||
Object.assign(newItem.binary, item.binary);
|
||||
}
|
||||
|
||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(data, filePath);
|
||||
const filePath = this.getNodeParameter('filePath', itemIndex) as string;
|
||||
const stream = await this.helpers.createReadStream(filePath);
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
|
||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(stream, filePath);
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
|
||||
Reference in New Issue
Block a user