From 0230c101dcaaa95af291ce3e0372bd62ddf4a05e Mon Sep 17 00:00:00 2001 From: Jiong Zhao Date: Mon, 29 Feb 2016 16:13:07 +0800 Subject: [PATCH] modify capture panic --- client.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/client.go b/client.go index 046e735..6e8ef80 100644 --- a/client.go +++ b/client.go @@ -588,6 +588,35 @@ func CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (in return DefaultClient.CapturePanic(f, tags, interfaces...) } +func CaptureRawPanic(panicErr interface{}, tags map[string]string, interfaces ...Interface) string { + return DefaultClient.CaptureRawPanic(panicErr, tags, interfaces...) +} + +func (client *Client) CaptureRawPanic(panicErr interface{}, tags map[string]string, interfaces ...Interface) string { + // Note: This doesn't need to check for client, because we still want to go through the defer/recover path + // Down the line, Capture will be noop'd, so while this does a _tiny_ bit of overhead constructing the + // *Packet just to be thrown away, this should not be the normal case. Could be refactored to + // be completely noop though if we cared. + var packet *Packet + switch rval := panicErr.(type) { + case nil: + return "" + case error: + packet = NewPacket(rval.Error(), append(append(interfaces, client.context.interfaces()...), NewException(rval, NewStacktrace(2, 3, client.includePaths)))...) + default: + rvalStr := fmt.Sprint(rval) + packet = NewPacket(rvalStr, append(append(interfaces, client.context.interfaces()...), NewException(errors.New(rvalStr), NewStacktrace(2, 3, client.includePaths)))...) + } + if tags == nil { + tags = map[string]string{"level":"panic"} + } else { + tags["level"] = "panic" + } + + errorID, _ := client.Capture(packet, tags) + return errorID +} + func (client *Client) Close() { close(client.queue) }