mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
msghub: Recover and log panics (#336)
Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/inbucket/inbucket/pkg/extension"
|
||||
"github.com/inbucket/inbucket/pkg/extension/event"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Length of msghub operation queue
|
||||
@@ -53,7 +54,7 @@ func (hub *Hub) Start(ctx context.Context) {
|
||||
close(hub.opChan)
|
||||
return
|
||||
case op := <-hub.opChan:
|
||||
op(hub)
|
||||
hub.runOp(op)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,3 +109,17 @@ func (hub *Hub) Sync() {
|
||||
}
|
||||
<-done
|
||||
}
|
||||
|
||||
func (hub *Hub) runOp(op func(*Hub)) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if err, ok := r.(error); ok {
|
||||
log.Error().Str("module", "msghub").Err(err).Msg("Operation panicked")
|
||||
} else {
|
||||
log.Error().Str("module", "msghub").Err(err).Msgf("Operation panicked: %s", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
op(hub)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user