Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Better error message when calling data transformation functions on a null value #10210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/workflow/src/Extensions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ export const convertToDateTime = (value: string | Date | DateTime): DateTime | u

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',
},
);
throw new ExpressionExtensionError(`${functionName} can't be used on ${String(value)} value`, {
description: `To ignore this error, add a ? to the variable before this function, e.g. my_var?.${functionName}`,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,15 @@ describe('tmpl Expression Parser', () => {
extend(undefined, 'toDateTime', []);
} catch (error) {
expect(error).toBeInstanceOf(ExpressionExtensionError);
expect(error).toHaveProperty(
'message',
'toDateTime() could not be called on "undefined" type',
);
expect(error).toHaveProperty('message', "toDateTime can't be used on undefined value");
}
});
test('input is null', () => {
try {
extend(null, 'startsWith', []);
} catch (error) {
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', () => {
Expand Down
Loading