fix(Set Node): Do not stringify null and undefined (#7313)

Github issue / Community forum post (link here to close automatically):
https://community.n8n.io/t/null-and-undefined-in-string-fields/31060/1
This commit is contained in:
Michael Kret
2023-10-03 11:18:33 +03:00
committed by GitHub
parent 3704760724
commit f0a66873b9
4 changed files with 24 additions and 5 deletions

View File

@@ -159,13 +159,26 @@ export const validateEntry = (
node: INode,
itemIndex: number,
ignoreErrors = false,
nodeVersion?: number,
) => {
let entryValue = entry[entry.type];
const name = entry.name;
const entryType = entry.type.replace('Value', '') as FieldType;
const description = `To fix the error try to change the type for the field "${name}" or activate the option “Ignore Type Conversion Errors” to apply a less strict type validation`;
if (entryType === 'string') {
if (typeof entryValue === 'object') {
if (nodeVersion && nodeVersion > 3 && (entryValue === undefined || entryValue === null)) {
if (ignoreErrors) {
return { name, value: null };
} else {
throw new NodeOperationError(
node,
`'${name}' expects a ${entryType} but we got '${String(entryValue)}' [item ${itemIndex}]`,
{ description },
);
}
} else if (typeof entryValue === 'object') {
entryValue = JSON.stringify(entryValue);
} else {
entryValue = String(entryValue);
@@ -179,7 +192,6 @@ export const validateEntry = (
validationResult.newValue = entry[entry.type];
} else {
const message = `${validationResult.errorMessage} [item ${itemIndex}]`;
const description = `To fix the error try to change the type for the field "${name}" or activate the option “Ignore Type Conversion Errors” to apply a less strict type validation`;
throw new NodeOperationError(node, message, {
itemIndex,
description,