mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Add rough sentry reporting to catch panic in the mojang textures decoder
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user