diff --git a/common/error.go b/common/error.go index 1d53f7e..b86ce38 100644 --- a/common/error.go +++ b/common/error.go @@ -25,6 +25,7 @@ var ( ErrConnection = errors.New("Connection error.") ErrNoActiveAgent = errors.New("No active agent.") ErrExecTimeOut = errors.New("Executing time out.") + ErrUnknown = errors.New("Unknown error.") ) func DisablePanic() {recover()} diff --git a/worker/worker.go b/worker/worker.go index 708a7f2..5d25b42 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -237,6 +237,15 @@ func (worker *Worker) SetId(id string) { // Execute the job. And send back the result. func (worker *Worker) exec(job *Job) (err error) { + defer func() { + if r := recover(); r != nil { + if e, ok := r.(error); ok { + err = e + } else { + err = common.ErrUnknown + } + } + } () if worker.limit != nil { <-worker.limit defer func() {