From cdfe4fff6cc1776c36a1a3949ac91d3d76c5820d Mon Sep 17 00:00:00 2001 From: mikespook Date: Mon, 4 Jun 2012 22:27:10 +0800 Subject: [PATCH] recover --- common/error.go | 1 + worker/worker.go | 9 +++++++++ 2 files changed, 10 insertions(+) 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() {