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

[BUG] - Handling negative time.Duration as interval param to Every func #600

Closed
husam-e opened this issue Oct 26, 2023 · 1 comment · Fixed by #603
Closed

[BUG] - Handling negative time.Duration as interval param to Every func #600

husam-e opened this issue Oct 26, 2023 · 1 comment · Fixed by #603
Labels
bug Something isn't working

Comments

@husam-e
Copy link

husam-e commented Oct 26, 2023

Describe the bug

Not sure if this is a bug, more of a question to confirm expected behavior: currently no error is returned when a negative time.Duration is provided as the interval param to Every. Is that intentional? Should it not return an error and fail fast, similar to when providing a negative int? Not clear to me what the intended behavior is for that.

To Reproduce

Steps to reproduce the behavior:

scheduler := gocron.NewScheduler(time.UTC)
interval := -1 * time.Second
_, err := scheduler.Every(interval).Do(func() { })

Version

v1.35.2

Expected behavior

err is returned non-nil, or otherwise behavior for negative Duration is documented on the Every function.

Additional context

Thinking it would be helpful as input validation to get an error in this scenario to immediately recognize invalid setup, just like how negative int values are treated as errors.

@husam-e husam-e added the bug Something isn't working label Oct 26, 2023
@husam-e husam-e changed the title [BUG] - Handling negative time.Duration as Every param for interval [BUG] - Handling negative time.Duration as interval param to Every func Oct 26, 2023
@JohnRoesler
Copy link
Contributor

@husam-e I agree this is a bug. it's solved in v2. If you'd like to open a PR for v1 feel free 😄

@JohnRoesler JohnRoesler added the v1 label Oct 28, 2023
husam-e added a commit to husam-e/gocron that referenced this issue Oct 30, 2023
JohnRoesler added a commit that referenced this issue Oct 30, 2023
…immediate error #600 (#603)

* fix(scheduler): ensure negative intervals given to `Every` return an immediate error #600

* Update Every func doc

* fix error check in tests

Co-authored-by: John Roesler <johnrroesler@gmail.com>

* Apply suggestions from code review

* Apply suggestions from code review

* Update scheduler_test.go

---------

Co-authored-by: John Roesler <johnrroesler@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants