Skip to content

Commit 8f12d0b

Browse files
committed
Use errors.New for non-formatted strings
1 parent cc3a1db commit 8f12d0b

File tree

5 files changed

+69
-67
lines changed

5 files changed

+69
-67
lines changed

errors.go

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
11
package gocron
22

3-
import "fmt"
3+
import (
4+
"errors"
5+
)
46

57
// Public error definitions
68
var (
7-
ErrCronJobInvalid = fmt.Errorf("gocron: CronJob: invalid crontab")
8-
ErrCronJobParse = fmt.Errorf("gocron: CronJob: crontab parse failure")
9-
ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil")
10-
ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil")
11-
ErrDailyJobHours = fmt.Errorf("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive")
12-
ErrDailyJobZeroInterval = fmt.Errorf("gocron: DailyJob: interval must be greater than 0")
13-
ErrDailyJobMinutesSeconds = fmt.Errorf("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
14-
ErrDurationJobIntervalZero = fmt.Errorf("gocron: DurationJob: time interval is 0")
15-
ErrDurationRandomJobMinMax = fmt.Errorf("gocron: DurationRandomJob: minimum duration must be less than maximum duration")
16-
ErrEventListenerFuncNil = fmt.Errorf("gocron: eventListenerFunc must not be nil")
17-
ErrJobNotFound = fmt.Errorf("gocron: job not found")
18-
ErrJobRunNowFailed = fmt.Errorf("gocron: Job: RunNow: scheduler unreachable")
19-
ErrMonthlyJobDays = fmt.Errorf("gocron: MonthlyJob: daysOfTheMonth must be between 31 and -31 inclusive, and not 0")
20-
ErrMonthlyJobAtTimeNil = fmt.Errorf("gocron: MonthlyJob: atTime within atTimes must not be nil")
21-
ErrMonthlyJobAtTimesNil = fmt.Errorf("gocron: MonthlyJob: atTimes must not be nil")
22-
ErrMonthlyJobDaysNil = fmt.Errorf("gocron: MonthlyJob: daysOfTheMonth must not be nil")
23-
ErrMonthlyJobHours = fmt.Errorf("gocron: MonthlyJob: atTimes hours must be between 0 and 23 inclusive")
24-
ErrMonthlyJobZeroInterval = fmt.Errorf("gocron: MonthlyJob: interval must be greater than 0")
25-
ErrMonthlyJobMinutesSeconds = fmt.Errorf("gocron: MonthlyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
26-
ErrNewJobTaskNil = fmt.Errorf("gocron: NewJob: Task must not be nil")
27-
ErrNewJobTaskNotFunc = fmt.Errorf("gocron: NewJob: Task.Function must be of kind reflect.Func")
28-
ErrNewJobWrongNumberOfParameters = fmt.Errorf("gocron: NewJob: Number of provided parameters does not match expected")
29-
ErrNewJobWrongTypeOfParameters = fmt.Errorf("gocron: NewJob: Type of provided parameters does not match expected")
30-
ErrOneTimeJobStartDateTimePast = fmt.Errorf("gocron: OneTimeJob: start must not be in the past")
31-
ErrStopExecutorTimedOut = fmt.Errorf("gocron: timed out waiting for executor to stop")
32-
ErrStopJobsTimedOut = fmt.Errorf("gocron: timed out waiting for jobs to finish")
33-
ErrStopSchedulerTimedOut = fmt.Errorf("gocron: timed out waiting for scheduler to stop")
34-
ErrWeeklyJobAtTimeNil = fmt.Errorf("gocron: WeeklyJob: atTime within atTimes must not be nil")
35-
ErrWeeklyJobAtTimesNil = fmt.Errorf("gocron: WeeklyJob: atTimes must not be nil")
36-
ErrWeeklyJobDaysOfTheWeekNil = fmt.Errorf("gocron: WeeklyJob: daysOfTheWeek must not be nil")
37-
ErrWeeklyJobHours = fmt.Errorf("gocron: WeeklyJob: atTimes hours must be between 0 and 23 inclusive")
38-
ErrWeeklyJobZeroInterval = fmt.Errorf("gocron: WeeklyJob: interval must be greater than 0")
39-
ErrWeeklyJobMinutesSeconds = fmt.Errorf("gocron: WeeklyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
40-
ErrPanicRecovered = fmt.Errorf("gocron: panic recovered")
41-
ErrWithClockNil = fmt.Errorf("gocron: WithClock: clock must not be nil")
42-
ErrWithContextNil = fmt.Errorf("gocron: WithContext: context must not be nil")
43-
ErrWithDistributedElectorNil = fmt.Errorf("gocron: WithDistributedElector: elector must not be nil")
44-
ErrWithDistributedLockerNil = fmt.Errorf("gocron: WithDistributedLocker: locker must not be nil")
45-
ErrWithDistributedJobLockerNil = fmt.Errorf("gocron: WithDistributedJobLocker: locker must not be nil")
46-
ErrWithIdentifierNil = fmt.Errorf("gocron: WithIdentifier: identifier must not be nil")
47-
ErrWithLimitConcurrentJobsZero = fmt.Errorf("gocron: WithLimitConcurrentJobs: limit must be greater than 0")
48-
ErrWithLocationNil = fmt.Errorf("gocron: WithLocation: location must not be nil")
49-
ErrWithLoggerNil = fmt.Errorf("gocron: WithLogger: logger must not be nil")
50-
ErrWithMonitorNil = fmt.Errorf("gocron: WithMonitor: monitor must not be nil")
51-
ErrWithNameEmpty = fmt.Errorf("gocron: WithName: name must not be empty")
52-
ErrWithStartDateTimePast = fmt.Errorf("gocron: WithStartDateTime: start must not be in the past")
53-
ErrWithStopDateTimePast = fmt.Errorf("gocron: WithStopDateTime: end must not be in the past")
54-
ErrStartTimeLaterThanEndTime = fmt.Errorf("gocron: WithStartDateTime: start must not be later than end")
55-
ErrStopTimeEarlierThanStartTime = fmt.Errorf("gocron: WithStopDateTime: end must not be earlier than start")
56-
ErrWithStopTimeoutZeroOrNegative = fmt.Errorf("gocron: WithStopTimeout: timeout must be greater than 0")
9+
ErrCronJobInvalid = errors.New("gocron: CronJob: invalid crontab")
10+
ErrCronJobParse = errors.New("gocron: CronJob: crontab parse failure")
11+
ErrDailyJobAtTimeNil = errors.New("gocron: DailyJob: atTime within atTimes must not be nil")
12+
ErrDailyJobAtTimesNil = errors.New("gocron: DailyJob: atTimes must not be nil")
13+
ErrDailyJobHours = errors.New("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive")
14+
ErrDailyJobZeroInterval = errors.New("gocron: DailyJob: interval must be greater than 0")
15+
ErrDailyJobMinutesSeconds = errors.New("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
16+
ErrDurationJobIntervalZero = errors.New("gocron: DurationJob: time interval is 0")
17+
ErrDurationRandomJobMinMax = errors.New("gocron: DurationRandomJob: minimum duration must be less than maximum duration")
18+
ErrEventListenerFuncNil = errors.New("gocron: eventListenerFunc must not be nil")
19+
ErrJobNotFound = errors.New("gocron: job not found")
20+
ErrJobRunNowFailed = errors.New("gocron: Job: RunNow: scheduler unreachable")
21+
ErrMonthlyJobDays = errors.New("gocron: MonthlyJob: daysOfTheMonth must be between 31 and -31 inclusive, and not 0")
22+
ErrMonthlyJobAtTimeNil = errors.New("gocron: MonthlyJob: atTime within atTimes must not be nil")
23+
ErrMonthlyJobAtTimesNil = errors.New("gocron: MonthlyJob: atTimes must not be nil")
24+
ErrMonthlyJobDaysNil = errors.New("gocron: MonthlyJob: daysOfTheMonth must not be nil")
25+
ErrMonthlyJobHours = errors.New("gocron: MonthlyJob: atTimes hours must be between 0 and 23 inclusive")
26+
ErrMonthlyJobZeroInterval = errors.New("gocron: MonthlyJob: interval must be greater than 0")
27+
ErrMonthlyJobMinutesSeconds = errors.New("gocron: MonthlyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
28+
ErrNewJobTaskNil = errors.New("gocron: NewJob: Task must not be nil")
29+
ErrNewJobTaskNotFunc = errors.New("gocron: NewJob: Task.Function must be of kind reflect.Func")
30+
ErrNewJobWrongNumberOfParameters = errors.New("gocron: NewJob: Number of provided parameters does not match expected")
31+
ErrNewJobWrongTypeOfParameters = errors.New("gocron: NewJob: Type of provided parameters does not match expected")
32+
ErrOneTimeJobStartDateTimePast = errors.New("gocron: OneTimeJob: start must not be in the past")
33+
ErrStopExecutorTimedOut = errors.New("gocron: timed out waiting for executor to stop")
34+
ErrStopJobsTimedOut = errors.New("gocron: timed out waiting for jobs to finish")
35+
ErrStopSchedulerTimedOut = errors.New("gocron: timed out waiting for scheduler to stop")
36+
ErrWeeklyJobAtTimeNil = errors.New("gocron: WeeklyJob: atTime within atTimes must not be nil")
37+
ErrWeeklyJobAtTimesNil = errors.New("gocron: WeeklyJob: atTimes must not be nil")
38+
ErrWeeklyJobDaysOfTheWeekNil = errors.New("gocron: WeeklyJob: daysOfTheWeek must not be nil")
39+
ErrWeeklyJobHours = errors.New("gocron: WeeklyJob: atTimes hours must be between 0 and 23 inclusive")
40+
ErrWeeklyJobZeroInterval = errors.New("gocron: WeeklyJob: interval must be greater than 0")
41+
ErrWeeklyJobMinutesSeconds = errors.New("gocron: WeeklyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
42+
ErrPanicRecovered = errors.New("gocron: panic recovered")
43+
ErrWithClockNil = errors.New("gocron: WithClock: clock must not be nil")
44+
ErrWithContextNil = errors.New("gocron: WithContext: context must not be nil")
45+
ErrWithDistributedElectorNil = errors.New("gocron: WithDistributedElector: elector must not be nil")
46+
ErrWithDistributedLockerNil = errors.New("gocron: WithDistributedLocker: locker must not be nil")
47+
ErrWithDistributedJobLockerNil = errors.New("gocron: WithDistributedJobLocker: locker must not be nil")
48+
ErrWithIdentifierNil = errors.New("gocron: WithIdentifier: identifier must not be nil")
49+
ErrWithLimitConcurrentJobsZero = errors.New("gocron: WithLimitConcurrentJobs: limit must be greater than 0")
50+
ErrWithLocationNil = errors.New("gocron: WithLocation: location must not be nil")
51+
ErrWithLoggerNil = errors.New("gocron: WithLogger: logger must not be nil")
52+
ErrWithMonitorNil = errors.New("gocron: WithMonitor: monitor must not be nil")
53+
ErrWithNameEmpty = errors.New("gocron: WithName: name must not be empty")
54+
ErrWithStartDateTimePast = errors.New("gocron: WithStartDateTime: start must not be in the past")
55+
ErrWithStopDateTimePast = errors.New("gocron: WithStopDateTime: end must not be in the past")
56+
ErrStartTimeLaterThanEndTime = errors.New("gocron: WithStartDateTime: start must not be later than end")
57+
ErrStopTimeEarlierThanStartTime = errors.New("gocron: WithStopDateTime: end must not be earlier than start")
58+
ErrWithStopTimeoutZeroOrNegative = errors.New("gocron: WithStopTimeout: timeout must be greater than 0")
5759
)
5860

5961
// internal errors
6062
var (
61-
errAtTimeNil = fmt.Errorf("errAtTimeNil")
62-
errAtTimesNil = fmt.Errorf("errAtTimesNil")
63-
errAtTimeHours = fmt.Errorf("errAtTimeHours")
64-
errAtTimeMinSec = fmt.Errorf("errAtTimeMinSec")
63+
errAtTimeNil = errors.New("errAtTimeNil")
64+
errAtTimesNil = errors.New("errAtTimesNil")
65+
errAtTimeHours = errors.New("errAtTimeHours")
66+
errAtTimeMinSec = errors.New("errAtTimeMinSec")
6567
)

example_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gocron_test
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78
"time"
@@ -58,7 +59,7 @@ var _ gocron.Locker = new(errorLocker)
5859
type errorLocker struct{}
5960

6061
func (e errorLocker) Lock(_ context.Context, _ string) (gocron.Lock, error) {
61-
return nil, fmt.Errorf("locked")
62+
return nil, errors.New("locked")
6263
}
6364

6465
func ExampleAfterLockError() {
@@ -120,7 +121,7 @@ func ExampleBeforeJobRunsSkipIfBeforeFuncErrors() {
120121
gocron.WithEventListeners(
121122
gocron.BeforeJobRunsSkipIfBeforeFuncErrors(
122123
func(jobID uuid.UUID, jobName string) error {
123-
return fmt.Errorf("error")
124+
return errors.New("error")
124125
},
125126
),
126127
),

examples/elector/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"log"
77
"time"
88

@@ -22,7 +22,7 @@ func (m myElector) IsLeader(_ context.Context) error {
2222
return nil
2323
}
2424
log.Printf("node %d is not leader", m.num)
25-
return fmt.Errorf("not leader")
25+
return errors.New("not leader")
2626
}
2727

2828
func main() {

scheduler_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gocron
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"io"
87
"os"
98
"sync"
@@ -1561,15 +1560,15 @@ type testElector struct {
15611560
func (t *testElector) IsLeader(ctx context.Context) error {
15621561
select {
15631562
case <-ctx.Done():
1564-
return fmt.Errorf("done")
1563+
return errors.New("done")
15651564
default:
15661565
}
15671566

15681567
t.mu.Lock()
15691568
defer t.mu.Unlock()
15701569
if t.leaderElected {
15711570
t.notLeader <- struct{}{}
1572-
return fmt.Errorf("already elected leader")
1571+
return errors.New("already elected leader")
15731572
}
15741573
t.leaderElected = true
15751574
return nil
@@ -1588,7 +1587,7 @@ func (t *testLocker) Lock(_ context.Context, _ string) (Lock, error) {
15881587
defer t.mu.Unlock()
15891588
if t.jobLocked {
15901589
t.notLocked <- struct{}{}
1591-
return nil, fmt.Errorf("job already locked")
1590+
return nil, errors.New("job already locked")
15921591
}
15931592
t.jobLocked = true
15941593
return &testLock{}, nil
@@ -1952,7 +1951,7 @@ func TestScheduler_WithEventListeners(t *testing.T) {
19521951
defer verifyNoGoroutineLeaks(t)
19531952

19541953
listenerRunCh := make(chan error, 1)
1955-
testErr := fmt.Errorf("test error")
1954+
testErr := errors.New("test error")
19561955
tests := []struct {
19571956
name string
19581957
tsk Task

util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gocron
22

33
import (
4-
"fmt"
4+
"errors"
55
"testing"
66
"time"
77

@@ -64,10 +64,10 @@ func TestCallJobFuncWithParams(t *testing.T) {
6464
{
6565
"function that returns an error",
6666
func() error {
67-
return fmt.Errorf("test error")
67+
return errors.New("test error")
6868
},
6969
nil,
70-
fmt.Errorf("test error"),
70+
errors.New("test error"),
7171
},
7272
{
7373
"function that returns no error",

0 commit comments

Comments
 (0)