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

Frontend + Backend CRON validation #13005

Merged
merged 13 commits into from
Feb 13, 2024
Merged

Conversation

mike12345567
Copy link
Collaborator

@mike12345567 mike12345567 commented Feb 9, 2024

Description

Adding some basic CRON validation to publishing, currently the error is not explained if it is hit - still need some frontend for this, but this now means that an error is provided to users when attempting to publish, and we can re-use this validation in the automation UI. Need to have both backend and frontend validation as invalid CRONs will already exist, backend makes sure these are error'd on.

Partially addresses: https://linear.app/budibase/issue/BUDI-7928/cron-expressions-should-be-validated

Error message:
image

Frontend:
image

  • Added the error message inline (Peter)
  • Also fixed an issue with preset being null for custom crons

…is not explained if it is hit - still need some frontend for this, but this now means that an error is provided to users when attempting to publish, and we can re-use this validation in the automation UI. Need to have both backend and frontend validation as invalid CRONs will already exist, backend makes sure these are error'd on.
@mike12345567 mike12345567 added the firestorm Data/Infra/Revenue Team label Feb 9, 2024
@mike12345567 mike12345567 self-assigned this Feb 9, 2024
@mike12345567 mike12345567 requested a review from a team as a code owner February 9, 2024 18:15
@mike12345567 mike12345567 requested review from samwho and removed request for a team February 9, 2024 18:15
Copy link
Collaborator

@melohagan melohagan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - nice enhancement 😄

packages/shared-core/src/helpers/cron.ts Outdated Show resolved Hide resolved
Comment on lines +16 to +31
function improveErrors(errors: string[]): string[] {
const finalErrors: string[] = []

for (let error of errors) {
if (error.includes(INPUT_CRON_START)) {
error = error.split(INPUT_CRON_START)[0].trim()
}
for (let [oldErr, newErr] of Object.entries(ERROR_SWAPS)) {
if (error.includes(oldErr)) {
error = error.replace(new RegExp(oldErr, "g"), newErr)
}
}
finalErrors.push(error)
}
return finalErrors
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eep. This concerns me. We're very sensitive to the cron-validate library changing their wording slightly and breaking our error messages. Makes me wonder if cron validation is actually complex enough to warrant using a library and munging its error messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we lock the library version then this shouldn't be too much of a problem - I doubt we will need to update this often - the error messages themselves are quite hard to read so just wanted to improve them ever so slightly.

Right now the way this works is it will spit out the raw errors anyway if they were to be updated for some reason, so it'll just look a bit less clear. The alternative is to just have the raw errors from the start, but I see no reason to not at least attempt to improve them/make them more human-readable.

EDIT: I've pinned the package version now - so should avoid issues with error messages being updated.

@mike12345567 mike12345567 changed the title Backend CRON validation Frontend + Backend CRON validation Feb 13, 2024
@mike12345567
Copy link
Collaborator Author

✅ the frontend side of it!

Copy link
Collaborator

@PClmnt PClmnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend LGTM!

@mike12345567 mike12345567 merged commit dcb0ec1 into master Feb 13, 2024
11 of 12 checks passed
@mike12345567 mike12345567 deleted the fix/add-cron-validation branch February 13, 2024 15:26
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
firestorm Data/Infra/Revenue Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants