fix(databases): parseScheduleAtFlag returns a validation error#1206
Merged
fix(databases): parseScheduleAtFlag returns a validation error#1206
parseScheduleAtFlag returns a validation error#1206Conversation
sc-zenokerr
requested changes
Mar 13, 2026
Contributor
sc-zenokerr
left a comment
There was a problem hiding this comment.
A suggestion otherwise LGTM.
cmd/databases.go
Outdated
| scheduleAtTimezone := s[1] | ||
|
|
||
| // If client writes "4:00", we only want to keep "4" in scheduleAtTime | ||
| scheduleAtTimeSplit := strings.SplitN(scheduleAtTime, ":", 2) |
Contributor
There was a problem hiding this comment.
Question, do we want to be prescriptive or accommodating about the format allowed?
If we allow 4 and 4:00 do we want to allow 04 and 04:00 or 4h and 4h00 etc... where is the line drawn.
If we want to be accommodating I would suggest replacing the scheduleAtTimeSplit with something more general, such as:
re := regexp.MustCompile(`([:hH].*)|[0]+`)
scheduleAtHour, err := strconv.Atoi(re.ReplaceAllString(scheduleAtTime, ""))
as this would accommodate lots of different formats e.g:
"4",
"4h",
"4H",
"04h",
"4:00",
"4:12",
"04:00",
"04:12",
"09:00",
"09",
"4h:45",
I made a goplayground here to test this for myself: https://go.dev/play/p/UxHf9xVmiCJ
Member
Author
There was a problem hiding this comment.
Great idea, thanks. Done in 40bdb7d. I also took the opportunity to add a unit test for parseScheduleAtFlag to ensure we don't break anything.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The error message is now clearer if the client does not provide a good format. For example:
And I updated the parsing function to be compatible with
4:00(and not only4).Fix #1106