mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
feat: Better error when calling expression function on input that is undefined or null (#10009)
This commit is contained in:
@@ -17,6 +17,7 @@ import type { ExpressionChunk, ExpressionCode } from './ExpressionParser';
|
||||
import { joinExpression, splitExpression } from './ExpressionParser';
|
||||
import { booleanExtensions } from './BooleanExtensions';
|
||||
import type { ExtensionMap } from './Extensions';
|
||||
import { checkIfValueDefinedOrThrow } from './utils';
|
||||
|
||||
const EXPRESSION_EXTENDER = 'extend';
|
||||
const EXPRESSION_EXTENDER_OPTIONAL = 'extendOptional';
|
||||
@@ -514,6 +515,7 @@ export function extend(input: unknown, functionName: string, args: unknown[]) {
|
||||
// any types have a function with that name. Then throw an error
|
||||
// letting the user know the available types.
|
||||
if (!foundFunction) {
|
||||
checkIfValueDefinedOrThrow(input, functionName);
|
||||
const haveFunction = EXTENSION_OBJECTS.filter((v) => functionName in v.functions);
|
||||
if (!haveFunction.length) {
|
||||
// This shouldn't really be possible but we should cover it anyway
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { ExpressionExtensionError } from '../errors/expression-extension.error';
|
||||
|
||||
// Utility functions and type guards for expression extensions
|
||||
|
||||
@@ -17,3 +18,15 @@ export const convertToDateTime = (value: string | Date | DateTime): DateTime | u
|
||||
}
|
||||
return converted;
|
||||
};
|
||||
|
||||
export function checkIfValueDefinedOrThrow<T>(value: T, functionName: string): void {
|
||||
if (value === undefined || value === null) {
|
||||
throw new ExpressionExtensionError(
|
||||
`${functionName}() could not be called on "${String(value)}" type`,
|
||||
{
|
||||
description:
|
||||
'You are trying to access a field that does not exist, modify your expression or set a default value',
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user