Skip to content

Commit

Permalink
add recover when event listeners are called
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Apr 20, 2022
1 parent 4d1c199 commit 0f11391
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lavalink/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"runtime/debug"
"time"

"github.com/disgoorg/snowflake"
Expand Down Expand Up @@ -377,6 +378,12 @@ func (p *DefaultPlayer) OnPlayerUpdate(state PlayerState) {
}

func (p *DefaultPlayer) EmitEvent(caller func(l interface{})) {
defer func() {
if r := recover(); r != nil {
p.lavalink.Logger().Errorf("recovered from panic in event listener: %#v\nstack: %s", r, string(debug.Stack()))
return
}
}()
for _, listener := range p.listeners {
caller(listener)
}
Expand Down

0 comments on commit 0f11391

Please sign in to comment.