mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +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
@@ -67,6 +67,7 @@ import {
|
||||
ITriggerFunctions,
|
||||
IWebhookFunctions,
|
||||
BinaryMetadata,
|
||||
FileSystemHelperFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { Agent } from 'https';
|
||||
@@ -93,6 +94,8 @@ import axios, {
|
||||
} from 'axios';
|
||||
import url, { URL, URLSearchParams } from 'url';
|
||||
import type { Readable } from 'stream';
|
||||
import { access as fsAccess } from 'fs/promises';
|
||||
import { createReadStream } from 'fs';
|
||||
|
||||
import { BinaryDataManager } from './BinaryDataManager';
|
||||
import type { IResponseError, IWorkflowSettings } from './Interfaces';
|
||||
@@ -1997,6 +2000,21 @@ const getRequestHelperFunctions = (
|
||||
},
|
||||
});
|
||||
|
||||
const getFileSystemHelperFunctions = (node: INode): FileSystemHelperFunctions => ({
|
||||
async createReadStream(filePath) {
|
||||
try {
|
||||
await fsAccess(filePath);
|
||||
} catch (error) {
|
||||
throw error.code === 'ENOENT'
|
||||
? new NodeOperationError(node, error, {
|
||||
message: `The file "${String(filePath)}" could not be accessed.`,
|
||||
})
|
||||
: error;
|
||||
}
|
||||
return createReadStream(filePath);
|
||||
},
|
||||
});
|
||||
|
||||
const getBinaryHelperFunctions = ({
|
||||
executionId,
|
||||
}: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({
|
||||
@@ -2292,6 +2310,7 @@ export function getExecuteFunctions(
|
||||
},
|
||||
helpers: {
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getFileSystemHelperFunctions(node),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
getBinaryDataBuffer: async (itemIndex, propertyName, inputIndex = 0) =>
|
||||
getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex),
|
||||
|
||||
Reference in New Issue
Block a user