Add rough sentry reporting to catch panic in the mojang textures decoder

This commit is contained in:
ErickSkrauch
2020-04-29 21:15:13 +03:00
parent 33b286cba0
commit 8001eab9db
6 changed files with 39 additions and 16 deletions

View File

@@ -1,9 +1,12 @@
package mojangtextures
import (
"fmt"
"sync"
"time"
"github.com/getsentry/raven-go"
"github.com/elyby/chrly/api/mojang"
"github.com/tevino/abool"
@@ -75,9 +78,22 @@ func (s *InMemoryTexturesStorage) GetTextures(uuid string) (*mojang.SignedTextur
func (s *InMemoryTexturesStorage) StoreTextures(uuid string, textures *mojang.SignedTexturesResponse) {
var timestamp int64
if textures != nil {
decoded := textures.DecodeTextures()
if decoded == nil {
panic("unable to decode textures")
decoded, err := textures.DecodeTextures()
if err != nil {
tags := map[string]string{
"textures.id": textures.Id,
"textures.name": textures.Name,
}
for i, prop := range textures.Props {
tags[fmt.Sprintf("textures.props[%d].name", i)] = prop.Name
tags[fmt.Sprintf("textures.props[%d].value", i)] = prop.Value
tags[fmt.Sprintf("textures.props[%d].signature", i)] = prop.Signature
}
raven.CaptureErrorAndWait(err, tags)
panic(err)
}
timestamp = decoded.Timestamp

View File

@@ -116,7 +116,7 @@ func TestInMemoryTexturesStorage_StoreTextures(t *testing.T) {
Props: []*mojang.Property{},
}
assert.PanicsWithValue(t, "unable to decode textures", func() {
assert.PanicsWithError(t, "unable to find the textures property", func() {
storage := NewInMemoryTexturesStorage()
storage.StoreTextures("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", toStore)
})