mirror of
https://github.com/elyby/chrly.git
synced 2024-11-26 16:51:59 +05:30
Add rough sentry reporting to catch panic in the mojang textures decoder
This commit is contained in:
parent
33b286cba0
commit
8001eab9db
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@ -265,7 +265,7 @@
|
||||
version = "v0.1.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:381bcbeb112a51493d9d998bbba207a529c73dbb49b3fd789e48c63fac1f192c"
|
||||
digest = "1:cc4eb6813da8d08694e557fcafae8fcc24f47f61a0717f952da130ca9a486dfc"
|
||||
name = "github.com/stretchr/testify"
|
||||
packages = [
|
||||
"assert",
|
||||
@ -274,8 +274,8 @@
|
||||
"suite",
|
||||
]
|
||||
pruneopts = ""
|
||||
revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053"
|
||||
version = "v1.3.0"
|
||||
revision = "3ebf1ddaeb260c4b1ae502a01c7844fa8c1fa0e9"
|
||||
version = "v1.5.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -3,6 +3,7 @@ package mojang
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -24,7 +25,7 @@ type SignedTexturesResponse struct {
|
||||
decodedTextures *TexturesProp
|
||||
}
|
||||
|
||||
func (t *SignedTexturesResponse) DecodeTextures() *TexturesProp {
|
||||
func (t *SignedTexturesResponse) DecodeTextures() (*TexturesProp, error) {
|
||||
if t.decodedTextures == nil {
|
||||
var texturesProp string
|
||||
for _, prop := range t.Props {
|
||||
@ -35,14 +36,18 @@ func (t *SignedTexturesResponse) DecodeTextures() *TexturesProp {
|
||||
}
|
||||
|
||||
if texturesProp == "" {
|
||||
return nil
|
||||
return nil, errors.New("unable to find the textures property")
|
||||
}
|
||||
|
||||
decodedTextures, err := DecodeTextures(texturesProp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
decodedTextures, _ := DecodeTextures(texturesProp)
|
||||
t.decodedTextures = decodedTextures
|
||||
}
|
||||
|
||||
return t.decodedTextures
|
||||
return t.decodedTextures, nil
|
||||
}
|
||||
|
||||
type Property struct {
|
||||
|
@ -20,7 +20,8 @@ func TestSignedTexturesResponse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
textures := obj.DecodeTextures()
|
||||
textures, err := obj.DecodeTextures()
|
||||
testify.Nil(t, err)
|
||||
testify.Equal(t, "3e3ee6c35afa48abb61e8cd8c42fc0d9", textures.ProfileID)
|
||||
})
|
||||
|
||||
@ -30,7 +31,8 @@ func TestSignedTexturesResponse(t *testing.T) {
|
||||
Name: "mock",
|
||||
Props: []*Property{},
|
||||
}
|
||||
textures := obj.DecodeTextures()
|
||||
textures, err := obj.DecodeTextures()
|
||||
testify.Errorf(t, err, "unable to find the textures property")
|
||||
testify.Nil(t, textures)
|
||||
})
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (ctx *Skinsystem) skinHandler(response http.ResponseWriter, request *http.R
|
||||
return
|
||||
}
|
||||
|
||||
texturesProp := mojangTextures.DecodeTextures()
|
||||
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||
skin := texturesProp.Textures.Skin
|
||||
if skin == nil {
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
@ -104,7 +104,7 @@ func (ctx *Skinsystem) capeHandler(response http.ResponseWriter, request *http.R
|
||||
return
|
||||
}
|
||||
|
||||
texturesProp := mojangTextures.DecodeTextures()
|
||||
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||
cape := texturesProp.Textures.Cape
|
||||
if cape == nil {
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
@ -162,7 +162,7 @@ func (ctx *Skinsystem) texturesHandler(response http.ResponseWriter, request *ht
|
||||
return
|
||||
}
|
||||
|
||||
texturesProp := mojangTextures.DecodeTextures()
|
||||
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||
if texturesProp == nil {
|
||||
ctx.Emit("skinsystem:error", errors.New("unable to find textures property"))
|
||||
apiServerError(response)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user