From d2041b69a164aa86658197050c16abddedb1d014 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sat, 24 Oct 2015 02:40:20 +0300 Subject: [PATCH] Handle panic debug on the Satan side --- daemon.go | 10 +--------- satan.go | 8 +++++++- 2 files changed, 8 insertions(+), 10 deletions(-) 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 }