Skip to content

Commit 3848673

Browse files
authored
fix(core): Account for readonly properties when replacing circular references (#18408)
1 parent 18137e1 commit 3848673

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/workflow/src/utils.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { ApplicationError } from '@n8n/errors';
12
import { parse as esprimaParse, Syntax } from 'esprima-next';
23
import type { Node as SyntaxNode, ExpressionStatement } from 'esprima-next';
34
import FormData from 'form-data';
45
import merge from 'lodash/merge';
56

67
import { ALPHABET } from './constants';
7-
import { ApplicationError } from '@n8n/errors';
88
import { ExecutionCancelledError } from './errors/execution-cancelled.error';
99
import type { BinaryFileType, IDisplayOptions, INodeProperties, JsonObject } from './interfaces';
10+
import * as LoggerProxy from './logger-proxy';
1011

1112
const readStreamClasses = new Set(['ReadStream', 'Readable', 'ReadableStream']);
1213

@@ -181,7 +182,18 @@ export const replaceCircularReferences = <T>(value: T, knownObjects = new WeakSe
181182
knownObjects.add(value);
182183
const copy = (Array.isArray(value) ? [] : {}) as T;
183184
for (const key in value) {
184-
copy[key] = replaceCircularReferences(value[key], knownObjects);
185+
try {
186+
copy[key] = replaceCircularReferences(value[key], knownObjects);
187+
} catch (error: unknown) {
188+
if (
189+
error instanceof TypeError &&
190+
error.message.includes('Cannot assign to read only property')
191+
) {
192+
LoggerProxy.error('Error while replacing circular references: ' + error.message, { error });
193+
continue; // Skip properties that cannot be assigned to (readonly, non-configurable, etc.)
194+
}
195+
throw error;
196+
}
185197
}
186198
knownObjects.delete(value);
187199
return copy;

0 commit comments

Comments
 (0)