From 98d280240e2d05bcfed13a12c8595ae68cb8cc09 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 3 Mar 2021 01:32:38 +0100 Subject: [PATCH] Resolves #28. We didn't manage to catch this error during testing, so we're normalizing its handling and hope that this will not happen again --- db/redis/redis.go | 15 ++++----------- db/redis/redis_integration_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/db/redis/redis.go b/db/redis/redis.go index 6336551..f76fa9f 100644 --- a/db/redis/redis.go +++ b/db/redis/redis.go @@ -4,12 +4,12 @@ import ( "bytes" "compress/zlib" "encoding/json" + "fmt" "io" "strconv" "strings" "time" - "github.com/getsentry/raven-go" "github.com/mediocregopher/radix.v2/pool" "github.com/mediocregopher/radix.v2/redis" "github.com/mediocregopher/radix.v2/util" @@ -205,17 +205,10 @@ func findMojangUuidByUsername(username string, conn util.Cmder) (string, bool, e data, _ := response.Str() parts := strings.Split(data, ":") - // Temporary debug statement to investigate https://github.com/elyby/chrly/issues/28 + // https://github.com/elyby/chrly/issues/28 if len(parts) < 2 { - raven.Capture(raven.NewPacketWithExtra( - "mojangUsernameToUuid hash contains corrupted data", - raven.Extra{ - "rawValue": "hello world", - "username": "this is username", - }, - ), map[string]string{}) - - return "", false, nil + conn.Cmd("HDEL", mojangUsernameToUuidKey, key) + return "", false, fmt.Errorf("Got unexpected response from the mojangUsernameToUuid hash: \"%s\"", data) } timestamp, _ := strconv.ParseInt(parts[1], 10, 64) diff --git a/db/redis/redis_integration_test.go b/db/redis/redis_integration_test.go index 3073c84..fd9c078 100644 --- a/db/redis/redis_integration_test.go +++ b/db/redis/redis_integration_test.go @@ -357,6 +357,22 @@ func (suite *redisTestSuite) TestGetUuid() { resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock") suite.Require().True(resp.IsType(redis.Nil), "should cleanup expired records") }) + + suite.RunSubTest("exists, but corrupted record", func() { + suite.cmd("HSET", + "hash:mojang-username-to-uuid", + "mock", + "corrupted value", + ) + + uuid, found, err := suite.Redis.GetUuid("Mock") + suite.Require().Empty(uuid) + suite.Require().False(found) + suite.Require().Error(err, "Got unexpected response from the mojangUsernameToUuid hash: \"corrupted value\"") + + resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock") + suite.Require().True(resp.IsType(redis.Nil), "should cleanup expired records") + }) } func (suite *redisTestSuite) TestStoreUuid() {