Created
June 26, 2017 13:22
-
-
Save bench/58ad92ebb0e3e7c25721712311703b18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PanicFilter struct { | |
mq.Handler | |
logger *log.Logger | |
} | |
func (f PanicFilter) Handle(d amqp.Delivery) error { | |
defer func() { | |
if panic := recover(); panic != nil { | |
defer d.Nack(false, false) // might have been ACK/NACK already, but for safety. | |
_, file, line, ok := runtime.Caller(4) | |
if !ok { | |
return | |
} | |
stack := make([]byte, 4096) | |
stack = stack[:runtime.Stack(stack, false)] | |
f.logger.Printf("Trapped panic [%s] while handling delivery (%s, line %d)\nStack:\n%s", panic, file, line, string(stack)) | |
} | |
}() | |
return f.Handler.Handle(d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment