feat: enhance error handling with JobError struct and update extractor logic
This commit is contained in:
33
cmd/go_migrate/job-error-handler.go
Normal file
33
cmd/go_migrate/job-error-handler.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type JobError struct {
|
||||
ShouldCancelJob bool
|
||||
Msg string
|
||||
Prev error
|
||||
}
|
||||
|
||||
func (e *JobError) Error() string {
|
||||
if e.Prev != nil {
|
||||
return fmt.Sprintf("%s: %v", e.Msg, e.Prev)
|
||||
}
|
||||
|
||||
return e.Msg
|
||||
}
|
||||
|
||||
func jobErrorHandler(chErrorsIn <-chan JobError) error {
|
||||
for err := range chErrorsIn {
|
||||
if err.ShouldCancelJob {
|
||||
return &err
|
||||
}
|
||||
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user