1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-09-06 00:43:20 +00:00

Port sp0rkle's panic recovery back into goirc.

This commit is contained in:
Alex Bramley 2013-03-10 13:30:00 +00:00
parent 5f2665dde8
commit ac9d05efa2
3 changed files with 44 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package client
import (
"github.com/fluffle/golog/logging"
"runtime"
"strings"
"sync"
)
@ -45,8 +46,9 @@ type hNode struct {
handler Handler
}
// A hNode implements both Handler...
// A hNode implements both Handler (with configurable panic recovery)...
func (hn *hNode) Handle(conn *Conn, line *Line) {
defer conn.cfg.Recover(conn, line)
hn.handler.Handle(conn, line)
}
@ -141,3 +143,10 @@ func (conn *Conn) HandleFunc(name string, hf HandlerFunc) Remover {
func (conn *Conn) dispatch(line *Line) {
conn.handlers.dispatch(conn, line)
}
func (conn *Conn) LogPanic(line *Line) {
if err := recover(); err != nil {
_, f, l, _ := runtime.Caller(2)
logging.Error("%s:%d: panic: %v", f, l, err)
}
}