mirror of https://github.com/go-co-op/gocron.git
wrap ErrPanicRecovered with recoverData (#749)
This commit is contained in:
parent
9d27ea8673
commit
970c5399bc
|
|
@ -2,6 +2,7 @@ package gocron
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -387,7 +388,7 @@ func (e *executor) callJobWithRecover(j internalJob) (err error) {
|
|||
_ = callJobFuncWithParams(j.afterJobRunsWithPanic, j.id, j.name, recoverData)
|
||||
|
||||
// if panic is occurred, we should return an error
|
||||
err = ErrPanicRecovered
|
||||
err = fmt.Errorf("%w from %v", ErrPanicRecovered, recoverData)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -646,6 +646,7 @@ func TestJob_NextRuns(t *testing.T) {
|
|||
|
||||
func TestJob_PanicOccurred(t *testing.T) {
|
||||
gotCh := make(chan any)
|
||||
errCh := make(chan error)
|
||||
s := newTestScheduler(t)
|
||||
_, err := s.NewJob(
|
||||
DurationJob(10*time.Millisecond),
|
||||
|
|
@ -656,6 +657,8 @@ func TestJob_PanicOccurred(t *testing.T) {
|
|||
WithEventListeners(
|
||||
AfterJobRunsWithPanic(func(_ uuid.UUID, _ string, recoverData any) {
|
||||
gotCh <- recoverData
|
||||
}), AfterJobRunsWithError(func(_ uuid.UUID, _ string, err error) {
|
||||
errCh <- err
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
|
@ -665,6 +668,11 @@ func TestJob_PanicOccurred(t *testing.T) {
|
|||
got := <-gotCh
|
||||
require.EqualError(t, got.(error), "runtime error: integer divide by zero")
|
||||
|
||||
err = <-errCh
|
||||
require.ErrorIs(t, err, ErrPanicRecovered)
|
||||
require.EqualError(t, err, "gocron: panic recovered from runtime error: integer divide by zero")
|
||||
|
||||
require.NoError(t, s.Shutdown())
|
||||
close(gotCh)
|
||||
close(errCh)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue