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

@@ -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 {

View File

@@ -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)
})
}