You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library panics if a time is malformed. Specifically in this case if the user forgets a preceeding zero, which I feel is probably a relatively easy mistake to make. I beat my head against the wall for an hour or so on this one before intuition lead me to try putting a zero in front of it.
To Reproduce
Minimal pathological example based on docs.
package main
import (
"fmt""time""github.com/go-co-op/gocron"
)
functask() {
fmt.Println("I am running task.")
}
functaskWithParams(aint, bstring) {
fmt.Println(a, b)
}
funcmain() {
// defines a new scheduler that schedules and runs jobss1:=gocron.NewScheduler(time.UTC)
// Do jobs with paramss1.Every(1).Day().At("1:00").StartImmediately().Do(taskWithParams, 1, "hello")
s1.StartBlocking()
}
Running this results in the following:
panic: reflect: call of reflect.Value.Type on zero Value
goroutine 5 [running]:
reflect.Value.Type(0x0, 0x0, 0x0, 0x0, 0x0)
/Users/me/opt/go/src/reflect/value.go:1872 +0x183
github.com/go-co-op/gocron.callJobFuncWithParams(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/me/go/src/github.com/go-co-op/gocron/gocron.go:53 +0xc5
github.com/go-co-op/gocron.(*Job).run(0xc0000c4000)
/Users/me/go/src/github.com/go-co-op/gocron/job.go:43 +0xd4
created by github.com/go-co-op/gocron.(*Scheduler).run
/Users/me/go/src/github.com/go-co-op/gocron/scheduler.go:185 +0x167
Looks like it comes down to bad examples by us not showing error checking when creating the schedule and our regex that parses time did not accept hours without leading zeros - fix incoming. Thanks for calling this out!
It's erroring when the At() func is called and so the job is nil which is causing the panic.
If you do this, it will fatal out with an error:
package main
import (
"fmt"
"log"
"time"
"github.com/go-co-op/gocron"
)
func taskWithParams(a int, b string) {
fmt.Println(a, b)
}
func main() {
// defines a new scheduler that schedules and runs jobs
s1 := gocron.NewScheduler(time.UTC)
// Do jobs with params
_, err := s1.Every(1).Day().At("1:00").StartImmediately().Do(taskWithParams, 1, "hello")
if err != nil {
log.Fatalf("error creating schedule: %v", err)
}
s1.StartBlocking()
}
Describe the bug
The library panics if a time is malformed. Specifically in this case if the user forgets a preceeding zero, which I feel is probably a relatively easy mistake to make. I beat my head against the wall for an hour or so on this one before intuition lead me to try putting a zero in front of it.
To Reproduce
Minimal pathological example based on docs.
Running this results in the following:
Not particularly descriptive. :(
Steps to reproduce the behavior:
go build
Version
25952fd
Expected behavior
You should find a way to present a meaningful error message to the user here, even if you DO have to panic.
The text was updated successfully, but these errors were encountered: