mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
fix: Better error message when calling data transformation functions on a null value (#10210)
This commit is contained in:
@@ -21,12 +21,8 @@ export const convertToDateTime = (value: string | Date | DateTime): DateTime | u
|
|||||||
|
|
||||||
export function checkIfValueDefinedOrThrow<T>(value: T, functionName: string): void {
|
export function checkIfValueDefinedOrThrow<T>(value: T, functionName: string): void {
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null) {
|
||||||
throw new ExpressionExtensionError(
|
throw new ExpressionExtensionError(`${functionName} can't be used on ${String(value)} value`, {
|
||||||
`${functionName}() could not be called on "${String(value)}" type`,
|
description: `To ignore this error, add a ? to the variable before this function, e.g. my_var?.${functionName}`,
|
||||||
{
|
});
|
||||||
description:
|
|
||||||
'You are trying to access a field that does not exist, modify your expression or set a default value',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,10 +250,7 @@ describe('tmpl Expression Parser', () => {
|
|||||||
extend(undefined, 'toDateTime', []);
|
extend(undefined, 'toDateTime', []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error).toBeInstanceOf(ExpressionExtensionError);
|
expect(error).toBeInstanceOf(ExpressionExtensionError);
|
||||||
expect(error).toHaveProperty(
|
expect(error).toHaveProperty('message', "toDateTime can't be used on undefined value");
|
||||||
'message',
|
|
||||||
'toDateTime() could not be called on "undefined" type',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('input is null', () => {
|
test('input is null', () => {
|
||||||
@@ -261,7 +258,7 @@ describe('tmpl Expression Parser', () => {
|
|||||||
extend(null, 'startsWith', []);
|
extend(null, 'startsWith', []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error).toBeInstanceOf(ExpressionExtensionError);
|
expect(error).toBeInstanceOf(ExpressionExtensionError);
|
||||||
expect(error).toHaveProperty('message', 'startsWith() could not be called on "null" type');
|
expect(error).toHaveProperty('message', "startsWith can't be used on null value");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('input should be converted to upper case', () => {
|
test('input should be converted to upper case', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user