Don't trigger a panic condition decoding event stats; closes pterodactyl/panel#3941

This commit is contained in:
Dane Everitt 2022-02-05 11:06:11 -05:00
parent 72476c61ec
commit 879dcd8df5
2 changed files with 11 additions and 4 deletions

View File

@ -55,12 +55,16 @@ func (b *Bus) Publish(topic string, data interface{}) {
// MustDecode decodes the event byte slice back into an events.Event struct or
// panics if an error is encountered during this process.
func MustDecode(data []byte) (e Event) {
MustDecodeTo(data, &e)
if err := DecodeTo(data, &e); err != nil {
panic(err)
}
return
}
func MustDecodeTo(data []byte, v interface{}) {
// DecodeTo decodes a byte slice of event data into the given interface.
func DecodeTo(data []byte, v interface{}) error {
if err := json.Unmarshal(data, &v); err != nil {
panic(errors.Wrap(err, "events: failed to decode event data into interface"))
return errors.Wrap(err, "events: failed to decode byte slice")
}
return nil
}

View File

@ -101,7 +101,10 @@ func (s *Server) StartEventListeners() {
Topic string
Data environment.Stats
}
events.MustDecodeTo(v, &stats)
if err := events.DecodeTo(v, &stats); err != nil {
s.Log().WithField("error", err).Warn("failed to decode server resource event")
return
}
s.resources.UpdateStats(stats.Data)
// If there is no disk space available at this point, trigger the server
// disk limiter logic which will start to stop the running instance.