forked from External/ergo
factor out some shared code
This commit is contained in:
parent
657ce0f1a4
commit
e0e4791f72
5 changed files with 66 additions and 52 deletions
19
irc/panic.go
Normal file
19
irc/panic.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) 2021 Shivaram Lingamneni
|
||||
// released under the MIT license
|
||||
|
||||
package irc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
// HandlePanic is a general-purpose panic handler for ad-hoc goroutines.
|
||||
// Because of the semantics of `recover`, it must be called directly
|
||||
// from the routine on whose call stack the panic would occur, with `defer`,
|
||||
// e.g. `defer server.HandlePanic()`
|
||||
func (server *Server) HandlePanic() {
|
||||
if r := recover(); r != nil {
|
||||
server.logger.Error("internal", fmt.Sprintf("Panic encountered: %v\n%s", r, debug.Stack()))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue