diff --git a/daemon.go b/daemon.go index 61f38d7..6e99f6b 100644 --- a/daemon.go +++ b/daemon.go @@ -172,16 +172,8 @@ func (d *BaseDaemon) base() *BaseDaemon { return d } -func (d *BaseDaemon) handlePanic() { - err := recover() - if err == nil { - return - } - - d.stats.registerError() +func (d *BaseDaemon) handlePanic(err interface{}) { if d.panicHandler != nil { d.panicHandler(err) } - log.Printf("Daemon %s recovered from a panic\nError: %v\n", d, err) - debug.PrintStack() } diff --git a/satan.go b/satan.go index 716acd6..0e5e41a 100644 --- a/satan.go +++ b/satan.go @@ -169,11 +169,17 @@ func (s *Satan) processSystemTask(t *task) { } func (s *Satan) processGeneralTask(t *task) { - defer t.daemon.base().handlePanic() defer func(start time.Time) { dur := time.Now().UnixNano() - start.UnixNano() t.daemon.base().stats.add(time.Duration(dur)) }(time.Now()) + defer func() { + if err := recover(); err != nil { + t.daemon.base().handlePanic(err) + log.Printf("Daemon %s recovered from a panic\nError: %v\n", t.daemon.base(), err) + debug.PrintStack() + } + }() t.actor() // <--- THE ACTION HAPPENS HERE }