Skip to content

fix(databases): parseScheduleAtFlag returns a validation error#1206

Merged
EtienneM merged 2 commits intomasterfrom
fix/1205/schedule_at_parse
Mar 16, 2026
Merged

fix(databases): parseScheduleAtFlag returns a validation error#1206
EtienneM merged 2 commits intomasterfrom
fix/1205/schedule_at_parse

Conversation

@EtienneM
Copy link
Member

@EtienneM EtienneM commented Mar 12, 2026

The error message is now clearer if the client does not provide a good format. For example:

 bsscalingo --app biniou backups-config --addon postgresql --schedule-at "azerty UTC"
 !     An error occurred:
       schedule-at=first field must be a digit representing the hour

And I updated the parsing function to be compatible with 4:00 (and not only 4).

Fix #1106

  • Add a changelog entry in the section "To Be Released" of CHANGELOG.md

@EtienneM EtienneM self-assigned this Mar 12, 2026
@EtienneM EtienneM marked this pull request as ready for review March 12, 2026 16:53
@EtienneM EtienneM requested review from a team and sc-zenokerr and removed request for a team March 12, 2026 16:53
Copy link
Contributor

@sc-zenokerr sc-zenokerr left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@EtienneM EtienneM requested a review from sc-zenokerr March 16, 2026 09:33
Copy link
Contributor

@sc-zenokerr sc-zenokerr left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks :)

@EtienneM EtienneM merged commit 682777b into master Mar 16, 2026
7 checks passed
@EtienneM EtienneM deleted the fix/1205/schedule_at_parse branch March 16, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backups-config: the "schedule-at" flag is not properly parsed

2 participants