-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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(Wait Node): Prevent waiting until invalid date #10523
Merged
ivov
merged 7 commits into
master
from
pay-1838-wait-node-without-specified-date-will-cause-all-executions
Aug 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28bfb7e
fix(Wait Node): Prevent waiting until invalid date
ivov 8cffec0
Merge branch 'master' into pay-1838-wait-node-without-specified-date-…
ivov 93dda02
Fix lint
ivov fd00d25
Merge branch 'master' into pay-1838-wait-node-without-specified-date-…
ivov 5473a98
Address feedback
ivov 0ec6343
Remove more private assertions
ivov 5349f85
Revert "Remove more private assertions"
ivov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ApplicationError } from 'n8n-workflow'; | ||
|
||
export function assertValidDate(candidate: unknown): asserts candidate is Date { | ||
if (!(candidate instanceof Date) || isNaN(candidate.getTime())) { | ||
throw new ApplicationError('Found invalid date', { extra: { date: candidate } }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { assertValidDate } from '@/assertions'; | ||
import { ApplicationError } from 'n8n-workflow'; | ||
|
||
describe('assertions', () => { | ||
describe('assertValidDate', () => { | ||
it('should throw if the candidate is not a date', () => { | ||
expect(() => assertValidDate(null)).toThrowError( | ||
new ApplicationError('Found invalid date', { extra: { date: null } }), | ||
); | ||
}); | ||
|
||
it('should throw if the candidate is an invalid date', () => { | ||
expect(() => assertValidDate(new Date('invalid'))).toThrowError( | ||
new ApplicationError('Found invalid date', { extra: { date: new Date('invalid') } }), | ||
); | ||
}); | ||
|
||
it('should not throw if the candidate is a valid date', () => { | ||
expect(() => assertValidDate(new Date())).not.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
IDisplayOptions, | ||
IWebhookFunctions, | ||
} from 'n8n-workflow'; | ||
import { WAIT_TIME_UNLIMITED } from 'n8n-workflow'; | ||
|
||
import { | ||
authenticationProperty, | ||
|
@@ -31,6 +31,7 @@ | |
import { formWebhook } from '../Form/utils'; | ||
import { updateDisplayOptions } from '../../utils/utilities'; | ||
import { Webhook } from '../Webhook/Webhook.node'; | ||
import { NodeOperationError } from 'n8n-workflow'; | ||
|
||
const toWaitAmount: INodeProperties = { | ||
displayName: 'Wait Amount', | ||
|
@@ -346,6 +347,7 @@ | |
}, | ||
default: '', | ||
description: 'The date and time to wait for before continuing', | ||
required: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A deeper fix would be having this param type fail when Since this is a rare edge case and that deeper change might have unexpected side effects, I'd rather prevent this at the |
||
}, | ||
|
||
// ---------------------------------- | ||
|
@@ -492,6 +494,13 @@ | |
} else { | ||
const dateTimeStr = context.getNodeParameter('dateTime', 0) as string; | ||
|
||
if (dateTimeStr === '') { | ||
throw new NodeOperationError( | ||
context.getNode(), | ||
'[Wait node] Cannot put execution to wait because `dateTime` parameter is empty. Please pick a specific date and time to wait until.', | ||
); | ||
} | ||
|
||
netroy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
waitTill = DateTime.fromFormat(dateTimeStr, "yyyy-MM-dd'T'HH:mm:ss", { | ||
zone: context.getTimezone(), | ||
}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of putting this here (where we'll then validate all dates), we should put this check in the wait node only when using a user input date.