Add recovery in handlePrivmsg

For an explanation of the voodoo, see
https://github.com/orfjackal/gospec/blob/master/src/gospec/recover.go#L44
https://github.com/orfjackal/gospec/blob/release/src/gospec/funcname.go#L22
https://github.com/orfjackal/gospec/blob/master/src/gospec/location.go#L43

Also note that in the next release of Go (or weekly.2011-04-13), cutoff
can be written using the code at
https://github.com/orfjackal/gospec/blob/master/src/gospec/funcname.go#L22
This commit is contained in:
raylu 2011-04-27 04:37:55 -04:00
parent f89b33a593
commit 4abd88f40b
1 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import (
irc "github.com/fluffle/goirc/client"
"fmt"
"strings"
"runtime"
"reflect"
"http"
"xml"
"strconv"
@ -59,6 +61,23 @@ func handlePrivmsg(conn *irc.Conn, line *irc.Line) {
return
}
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered from", r)
callers := make([]uintptr, 10)
runtime.Callers(4, callers)
cutoff := runtime.FuncForPC(reflect.NewValue(handlePrivmsg).(*reflect.FuncValue).Get()).Entry()
for _, pc := range callers {
function := runtime.FuncForPC(pc - 1)
if function.Entry() == cutoff{
break
}
file, line := function.FileLine(pc - 1)
fmt.Printf("%s:%d\n\t%s\n", file, line, function.Name())
}
}
}()
target := line.Args[0]
if isChannel(target) {
// message to a channel