mirror of https://github.com/fluffle/goirc
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:
parent
f89b33a593
commit
4abd88f40b
19
handler.go
19
handler.go
|
@ -4,6 +4,8 @@ import (
|
||||||
irc "github.com/fluffle/goirc/client"
|
irc "github.com/fluffle/goirc/client"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"runtime"
|
||||||
|
"reflect"
|
||||||
"http"
|
"http"
|
||||||
"xml"
|
"xml"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -59,6 +61,23 @@ func handlePrivmsg(conn *irc.Conn, line *irc.Line) {
|
||||||
return
|
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]
|
target := line.Args[0]
|
||||||
if isChannel(target) {
|
if isChannel(target) {
|
||||||
// message to a channel
|
// message to a channel
|
||||||
|
|
Loading…
Reference in New Issue