From 973106d0b35b8205c0045d54d8213946d013c232 Mon Sep 17 00:00:00 2001 From: Arpit Bhayani Date: Thu, 5 Dec 2024 22:15:14 +0530 Subject: [PATCH] Error handling strreamlined --- docs/src/content/docs/commands/HSET.md | 8 +- .../commands/http/append_test.go | 12 +-- integration_tests/commands/http/bit_test.go | 12 +-- integration_tests/commands/http/bloom_test.go | 6 +- .../commands/http/check_type_test.go | 2 +- .../commands/http/getdel_test.go | 4 +- integration_tests/commands/http/getex_test.go | 8 +- .../commands/http/getrange_test.go | 2 +- .../commands/http/getset_test.go | 2 +- integration_tests/commands/http/hdel_test.go | 2 +- integration_tests/commands/http/hget_test.go | 2 +- integration_tests/commands/http/hlen_test.go | 2 +- integration_tests/commands/http/hscan_test.go | 2 +- integration_tests/commands/http/hset_test.go | 3 +- .../commands/http/hsetnx_test.go | 2 +- .../commands/http/hstrlen_test.go | 2 +- .../commands/http/json_arrpop_test.go | 2 +- integration_tests/commands/http/json_test.go | 4 +- .../commands/http/set_data_cmd_test.go | 16 ++-- integration_tests/commands/http/set_test.go | 2 +- integration_tests/commands/http/zcard_test.go | 2 +- .../commands/http/zpopmax_test.go | 2 +- integration_tests/commands/http/zrem_test.go | 2 +- integration_tests/commands/http/zset_test.go | 2 +- .../commands/resp/append_test.go | 14 ++-- integration_tests/commands/resp/bit_test.go | 12 +-- integration_tests/commands/resp/bloom_test.go | 6 +- .../commands/resp/check_type_test.go | 2 +- integration_tests/commands/resp/deque_test.go | 5 +- .../commands/resp/getdel_test.go | 4 +- integration_tests/commands/resp/getex_test.go | 8 +- .../commands/resp/getrange_test.go | 2 +- .../commands/resp/getset_test.go | 2 +- integration_tests/commands/resp/hdel_test.go | 2 +- .../commands/resp/hexists_test.go | 3 +- integration_tests/commands/resp/hget_test.go | 2 +- .../commands/resp/hgetall_test.go | 2 +- .../commands/resp/hincrby_test.go | 2 +- .../commands/resp/hincrbyfloat_test.go | 2 +- integration_tests/commands/resp/hkeys_test.go | 3 +- integration_tests/commands/resp/hlen_test.go | 2 +- integration_tests/commands/resp/hmget_test.go | 2 +- integration_tests/commands/resp/hmset_test.go | 5 +- integration_tests/commands/resp/hscan_test.go | 2 +- integration_tests/commands/resp/hset_test.go | 2 +- .../commands/resp/hsetnx_test.go | 2 +- .../commands/resp/hstrlen_test.go | 2 +- integration_tests/commands/resp/hvals_test.go | 3 +- integration_tests/commands/resp/json_test.go | 4 +- .../commands/resp/set_data_cmd_test.go | 8 +- integration_tests/commands/resp/set_test.go | 2 +- integration_tests/commands/resp/zcard_test.go | 2 +- .../commands/resp/zpopmax_test.go | 2 +- integration_tests/commands/resp/zrem_test.go | 2 +- integration_tests/commands/resp/zset_test.go | 2 +- .../commands/websocket/append_test.go | 10 +-- .../commands/websocket/bit_test.go | 12 +-- .../commands/websocket/bloom_test.go | 6 +- .../commands/websocket/getrange_test.go | 2 +- .../commands/websocket/hdel_test.go | 2 +- .../commands/websocket/hget_test.go | 2 +- .../commands/websocket/hincrby_test.go | 2 +- .../commands/websocket/hincrbyfloat_test.go | 2 +- .../commands/websocket/hlen_test.go | 2 +- .../commands/websocket/hscan_test.go | 2 +- .../commands/websocket/hset_test.go | 2 +- .../commands/websocket/json_test.go | 2 +- .../commands/websocket/set_test.go | 2 +- .../commands/websocket/zcard_test.go | 2 +- .../commands/websocket/zpopmax_test.go | 2 +- .../commands/websocket/zrem_test.go | 2 +- .../commands/websocket/zset_test.go | 4 +- internal/errors/errors.go | 4 +- internal/eval/eval.go | 2 +- internal/eval/eval_test.go | 84 +++++++++---------- internal/eval/store_eval.go | 2 +- internal/object/typeencoding.go | 4 +- 77 files changed, 188 insertions(+), 182 deletions(-) diff --git a/docs/src/content/docs/commands/HSET.md b/docs/src/content/docs/commands/HSET.md index 7028d17c6..eeb87d4c6 100644 --- a/docs/src/content/docs/commands/HSET.md +++ b/docs/src/content/docs/commands/HSET.md @@ -1,9 +1,9 @@ --- title: HSET -description: The `HSET` command in DiceDB is used to set the value of a field in a hash. If the hash does not exist, a new hash is created. If the field already exists in the hash, the value is updated. This command is useful for managing and storing key-value pairs within a hash data structure. +description: The `HSET` command in DiceDB is used to set the value of a field in a hash table. If the hash table does not exist, a new hash is created. If the field already exists in the hash table, the value is updated. This command is useful for managing and storing key-value pairs within a hash data structure. --- -The `HSET` command in DiceDB is used to set the value of a field in a hash. If the hash does not exist, a new hash is created. If the field already exists in the hash, the value is updated. This command is useful for managing and storing key-value pairs within a hash data structure. +The `HSET` command in DiceDB is used to set the value of a field in a hash table. If the hash table does not exist, a new hash is created. If the field already exists in the hash table, the value is updated. This command is useful for managing and storing key-value pairs within a hash data structure. ## Syntax @@ -22,12 +22,14 @@ HSET key field value [field value ...] ## Return Values +The number of fields that were added. + | Condition | Return Value | | ------------------------ | --------------------------------------------------------------------------- | | A new field added | `1` | | Existing field updated | `0` | | Multiple fields added | `Integer` (count of new fields) | -| Wrong data type | `(error) WRONGTYPE Operation against a key holding the wrong kind of value` | +| HSET on different type | `(error) WRONGTYPE Operation against a key holding the wrong kind of value` | | Incorrect Argument Count | `(error) ERR wrong number of arguments for 'hset' command` | ## Behaviour diff --git a/integration_tests/commands/http/append_test.go b/integration_tests/commands/http/append_test.go index 5c4150ae2..70020ea5f 100644 --- a/integration_tests/commands/http/append_test.go +++ b/integration_tests/commands/http/append_test.go @@ -64,7 +64,7 @@ func TestAPPEND(t *testing.T) { {Command: "LPUSH", Body: map[string]interface{}{"key": "m", "value": "bhima"}}, {Command: "APPEND", Body: map[string]interface{}{"key": "m", "value": "shankar"}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []HTTPCommand{ {Command: "del", Body: map[string]interface{}{"key": "m"}}, }, @@ -89,7 +89,7 @@ func TestAPPEND(t *testing.T) { {Command: "SADD", Body: map[string]interface{}{"key": "key", "value": "apple"}}, {Command: "APPEND", Body: map[string]interface{}{"key": "key", "value": "banana"}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []HTTPCommand{ {Command: "del", Body: map[string]interface{}{"key": "key"}}, }, @@ -100,7 +100,7 @@ func TestAPPEND(t *testing.T) { {Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": []string{"1", "one"}}}, {Command: "APPEND", Body: map[string]interface{}{"key": "myzset", "value": "two"}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []HTTPCommand{ {Command: "del", Body: map[string]interface{}{"key": "myzset"}}, }, @@ -185,10 +185,10 @@ func TestAPPEND(t *testing.T) { float64(0), float64(1), float64(1), - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), float64(6), - "WRONGTYPE Operation against a key holding the wrong kind of value", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), + diceerrors.ErrWrongTypeOperation.Error(), }, cleanup: []HTTPCommand{ {Command: "del", Body: map[string]interface{}{"key": "listKey"}}, diff --git a/integration_tests/commands/http/bit_test.go b/integration_tests/commands/http/bit_test.go index 1d6418cde..b9b47fda5 100644 --- a/integration_tests/commands/http/bit_test.go +++ b/integration_tests/commands/http/bit_test.go @@ -1002,21 +1002,21 @@ func TestBitfield(t *testing.T) { { Name: "BITFIELD on unsupported type of SET", Commands: []HTTPCommand{{Command: "SADD", Body: map[string]interface{}{"key": "bits", "values": []string{"a", "b", "c"}}}, {Command: "BITFIELD", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{float64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, { Name: "BITFIELD on unsupported type of JSON", Commands: []HTTPCommand{{Command: "json.set", Body: map[string]interface{}{"key": "bits", "path": "$", "value": "1"}}, {Command: "BITFIELD", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, { Name: "BITFIELD on unsupported type of HSET", Commands: []HTTPCommand{{Command: "HSET", Body: map[string]interface{}{"key": "bits", "field": "a", "value": "1"}}, {Command: "BITFIELD", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, @@ -1257,21 +1257,21 @@ func TestBitfieldRO(t *testing.T) { { Name: "BITFIELD_RO on unsupported type of SET", Commands: []HTTPCommand{{Command: "SADD", Body: map[string]interface{}{"key": "bits", "values": []string{"a", "b", "c"}}}, {Command: "BITFIELD_RO", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{float64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, { Name: "BITFIELD_RO on unsupported type of JSON", Commands: []HTTPCommand{{Command: "JSON.SET", Body: map[string]interface{}{"key": "bits", "path": "$", "value": "1"}}, {Command: "BITFIELD_RO", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, { Name: "BITFIELD_RO on unsupported type of HSET", Commands: []HTTPCommand{{Command: "HSET", Body: map[string]interface{}{"key": "bits", "field": "a", "value": "1"}}, {Command: "BITFIELD_RO", Body: map[string]interface{}{"key": "bits"}}}, - Expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []HTTPCommand{{Command: "DEL", Body: map[string]interface{}{"key": "bits"}}}, }, diff --git a/integration_tests/commands/http/bloom_test.go b/integration_tests/commands/http/bloom_test.go index 8d28958b9..6e631fca2 100644 --- a/integration_tests/commands/http/bloom_test.go +++ b/integration_tests/commands/http/bloom_test.go @@ -328,7 +328,7 @@ func TestBFEdgeCasesAndErrors(t *testing.T) { Body: map[string]interface{}{"key": "bf", "values": []interface{}{0.01, 1000}}, }, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "BF.ADD on a key holding a list", @@ -342,7 +342,7 @@ func TestBFEdgeCasesAndErrors(t *testing.T) { Body: map[string]interface{}{"key": "bf", "value": "item2"}, }, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "BF.INFO on a key holding a hash", @@ -356,7 +356,7 @@ func TestBFEdgeCasesAndErrors(t *testing.T) { Body: map[string]interface{}{"key": "bf"}, }, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, }, } for _, tc := range testCases { diff --git a/integration_tests/commands/http/check_type_test.go b/integration_tests/commands/http/check_type_test.go index 81127f284..c6f792d1f 100644 --- a/integration_tests/commands/http/check_type_test.go +++ b/integration_tests/commands/http/check_type_test.go @@ -10,7 +10,7 @@ import ( // This file may contain test cases for checking error messages across all commands func TestErrorsForSetData(t *testing.T) { exec := NewHTTPCommandExecutor() - setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value" + setErrorMsg := diceerrors.ErrWrongTypeOperation.Error() testCases := []struct { name string commands []HTTPCommand diff --git a/integration_tests/commands/http/getdel_test.go b/integration_tests/commands/http/getdel_test.go index 9233a0b90..8946f8d9e 100644 --- a/integration_tests/commands/http/getdel_test.go +++ b/integration_tests/commands/http/getdel_test.go @@ -73,7 +73,7 @@ func TestGetDel(t *testing.T) { {Command: "SADD", Body: map[string]interface{}{"key": "myset", "member": "member1"}}, {Command: "GETDEL", Body: map[string]interface{}{"key": "myset"}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { @@ -83,7 +83,7 @@ func TestGetDel(t *testing.T) { {Command: "GETDEL", Body: map[string]interface{}{"key": "k"}}, {Command: "JSON.GET", Body: map[string]interface{}{"key": "k"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", "1"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), "1"}, delays: []time.Duration{0, 0, 0}, }, } diff --git a/integration_tests/commands/http/getex_test.go b/integration_tests/commands/http/getex_test.go index 12fb9d03b..d3f3b0f72 100644 --- a/integration_tests/commands/http/getex_test.go +++ b/integration_tests/commands/http/getex_test.go @@ -217,7 +217,7 @@ func TestGetEx(t *testing.T) { {Command: "JSON.SET", Body: map[string]interface{}{"key": "KEY", "path": "$", "value": "1"}}, {Command: "GETEX", Body: map[string]interface{}{"key": "KEY"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, @@ -231,9 +231,9 @@ func TestGetEx(t *testing.T) { }, expected: []interface{}{ "OK", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), "OK", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), }, assertType: []string{"equal", "equal", "equal", "equal"}, delay: []time.Duration{0, 0, 0, 0}, @@ -244,7 +244,7 @@ func TestGetEx(t *testing.T) { {Command: "SADD", Body: map[string]interface{}{"key": "SKEY", "members": []interface{}{1, 2, 3}}}, {Command: "GETEX", Body: map[string]interface{}{"key": "SKEY"}}, }, - expected: []interface{}{float64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(3), diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, diff --git a/integration_tests/commands/http/getrange_test.go b/integration_tests/commands/http/getrange_test.go index e4c7c941e..2f9c822bf 100644 --- a/integration_tests/commands/http/getrange_test.go +++ b/integration_tests/commands/http/getrange_test.go @@ -67,7 +67,7 @@ func TestGETRANGE(t *testing.T) { {Command: "LPUSH", Body: map[string]interface{}{"key": "test3", "value": "shankar"}}, {Command: "GETRANGE", Body: map[string]interface{}{"key": "test3", "values": []interface{}{0, 7}}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []HTTPCommand{ {Command: "del", Body: map[string]interface{}{"key": "test3"}}, }, diff --git a/integration_tests/commands/http/getset_test.go b/integration_tests/commands/http/getset_test.go index 0072eee92..3e2d61577 100644 --- a/integration_tests/commands/http/getset_test.go +++ b/integration_tests/commands/http/getset_test.go @@ -52,7 +52,7 @@ func TestGetSet(t *testing.T) { {Command: "LPUSH", Body: map[string]interface{}{"key": "k1", "value": "val"}}, {Command: "GETSET", Body: map[string]interface{}{"key": "k1", "value": "v1"}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hdel_test.go b/integration_tests/commands/http/hdel_test.go index a955fc274..6afdb3e2b 100644 --- a/integration_tests/commands/http/hdel_test.go +++ b/integration_tests/commands/http/hdel_test.go @@ -74,7 +74,7 @@ func TestHDel(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "value"}}, {Command: "HDEL", Body: map[string]interface{}{"key": "string_key", "field": "field"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hget_test.go b/integration_tests/commands/http/hget_test.go index 364fdc0d2..4cf220e97 100644 --- a/integration_tests/commands/http/hget_test.go +++ b/integration_tests/commands/http/hget_test.go @@ -64,7 +64,7 @@ func TestHGet(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "value"}}, {Command: "HGET", Body: map[string]interface{}{"key": "string_key", "field": "field"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hlen_test.go b/integration_tests/commands/http/hlen_test.go index 91daef6f4..b54e89528 100644 --- a/integration_tests/commands/http/hlen_test.go +++ b/integration_tests/commands/http/hlen_test.go @@ -62,7 +62,7 @@ func TestHLen(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "key", "value": "value"}}, {Command: "HLEN", Body: map[string]interface{}{"key": "key"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hscan_test.go b/integration_tests/commands/http/hscan_test.go index d3c048210..d8b207573 100644 --- a/integration_tests/commands/http/hscan_test.go +++ b/integration_tests/commands/http/hscan_test.go @@ -41,7 +41,7 @@ func TestHScan(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "string_value"}}, {Command: "HSCAN", Body: map[string]interface{}{"values": []interface{}{"string_key", 0}}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/http/hset_test.go b/integration_tests/commands/http/hset_test.go index e17bf6574..7a88628df 100644 --- a/integration_tests/commands/http/hset_test.go +++ b/integration_tests/commands/http/hset_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + diceerrors "github.com/dicedb/dice/internal/errors" "github.com/stretchr/testify/assert" ) @@ -63,7 +64,7 @@ func TestHSet(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "value"}}, {Command: "HSET", Body: map[string]interface{}{"key": "string_key", "field": "field", "value": "value"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hsetnx_test.go b/integration_tests/commands/http/hsetnx_test.go index 133ab883c..b14acf21b 100644 --- a/integration_tests/commands/http/hsetnx_test.go +++ b/integration_tests/commands/http/hsetnx_test.go @@ -49,7 +49,7 @@ func TestHSetNX(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "key_nx_t4", "value": "v"}}, {Command: "HSETNX", Body: map[string]interface{}{"key": "key_nx_t4", "field": "f", "value": "v_new"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/hstrlen_test.go b/integration_tests/commands/http/hstrlen_test.go index 7e4685463..ec3227f3f 100644 --- a/integration_tests/commands/http/hstrlen_test.go +++ b/integration_tests/commands/http/hstrlen_test.go @@ -61,7 +61,7 @@ func TestHStrLen(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "key", "value": "value"}}, {Command: "HSTRLEN", Body: map[string]interface{}{"key": "key", "field": "field"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/http/json_arrpop_test.go b/integration_tests/commands/http/json_arrpop_test.go index b564a6a8f..a4c29ac0b 100644 --- a/integration_tests/commands/http/json_arrpop_test.go +++ b/integration_tests/commands/http/json_arrpop_test.go @@ -143,7 +143,7 @@ func TestJSONARRPOP(t *testing.T) { Body: map[string]interface{}{"key": "doc_new"}, }, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "nil response for arr pop", diff --git a/integration_tests/commands/http/json_test.go b/integration_tests/commands/http/json_test.go index 8a3b862ec..2072d4e1c 100644 --- a/integration_tests/commands/http/json_test.go +++ b/integration_tests/commands/http/json_test.go @@ -157,7 +157,7 @@ func TestJSONOperations(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "k1", "value": "1"}}, {Command: "JSON.GET", Body: map[string]interface{}{"key": "k1"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "Set Empty JSON Object", @@ -1286,7 +1286,7 @@ func TestJsonObjLen(t *testing.T) { commands: []HTTPCommand{ {Command: "json.objlen", Body: map[string]interface{}{"key": "c", "path": ".name"}}, }, - expected: []interface{}{"WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "JSON.OBJLEN with legacy path - inner existent path recursive object", diff --git a/integration_tests/commands/http/set_data_cmd_test.go b/integration_tests/commands/http/set_data_cmd_test.go index e850a7569..12f5a3e68 100644 --- a/integration_tests/commands/http/set_data_cmd_test.go +++ b/integration_tests/commands/http/set_data_cmd_test.go @@ -51,7 +51,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD multiple add and multiple kind of values", @@ -91,7 +91,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SCARD", Body: map[string]interface{}{"key": "foo"}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SMEMBERS", @@ -118,7 +118,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SMEMBERS", Body: map[string]interface{}{"key": "foo"}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SREM", @@ -146,7 +146,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SREM", Body: map[string]interface{}{"key": "foo", "value": "bar"}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SREM with non-existing value", @@ -188,7 +188,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SDIFF with subsequent key of wrong type", @@ -199,7 +199,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}}, }, assert_type: []string{"equal", "equal", "equal", "equal"}, - expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), float64(1), "OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SDIFF with non-existing first key", @@ -250,7 +250,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}}, }, assert_type: []string{"equal", "equal"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SINTER with subsequent key of wrong type", @@ -261,7 +261,7 @@ func TestSetDataCmd(t *testing.T) { {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}}, }, assert_type: []string{"equal", "equal", "equal", "equal"}, - expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), float64(1), "OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "SADD & SINTER with single key", diff --git a/integration_tests/commands/http/set_test.go b/integration_tests/commands/http/set_test.go index 84c10f8d8..c8798de6b 100644 --- a/integration_tests/commands/http/set_test.go +++ b/integration_tests/commands/http/set_test.go @@ -209,7 +209,7 @@ func TestSetWithOptions(t *testing.T) { {Command: "SADD", Body: map[string]interface{}{"key": "k", "value": "b"}}, {Command: "SET", Body: map[string]interface{}{"key": "k", "value": "v", "get": true}}, }, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/http/zcard_test.go b/integration_tests/commands/http/zcard_test.go index 29c869d97..a253b9bc9 100644 --- a/integration_tests/commands/http/zcard_test.go +++ b/integration_tests/commands/http/zcard_test.go @@ -34,7 +34,7 @@ func TestZCARD(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "string_value"}}, {Command: "ZCARD", Body: map[string]interface{}{"key": "string_key"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/http/zpopmax_test.go b/integration_tests/commands/http/zpopmax_test.go index 971f31924..9a3340aa8 100644 --- a/integration_tests/commands/http/zpopmax_test.go +++ b/integration_tests/commands/http/zpopmax_test.go @@ -22,7 +22,7 @@ func TestZPOPMAX(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "sortedSet", "value": "testString"}}, {Command: "ZPOPMAX", Body: map[string]interface{}{"key": "sortedSet"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "ZPOPMAX on existing key (without count argument)", diff --git a/integration_tests/commands/http/zrem_test.go b/integration_tests/commands/http/zrem_test.go index 733c5c793..a9a18f22f 100644 --- a/integration_tests/commands/http/zrem_test.go +++ b/integration_tests/commands/http/zrem_test.go @@ -34,7 +34,7 @@ func TestZREM(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "string_key", "value": "string_value"}}, {Command: "ZREM", Body: map[string]interface{}{"key": "string_key", "field": "string_value"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/http/zset_test.go b/integration_tests/commands/http/zset_test.go index 1b54678e9..ea3b7e810 100644 --- a/integration_tests/commands/http/zset_test.go +++ b/integration_tests/commands/http/zset_test.go @@ -22,7 +22,7 @@ func TestZPOPMIN(t *testing.T) { {Command: "SET", Body: map[string]interface{}{"key": "stringkey", "value": "string_value"}}, {Command: "ZPOPMIN", Body: map[string]interface{}{"key": "stringkey"}}, }, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", float64(1)}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), float64(1)}, }, { name: "ZPOPMIN on existing key (without count argument)", diff --git a/integration_tests/commands/resp/append_test.go b/integration_tests/commands/resp/append_test.go index 85829fa66..42afab5fc 100644 --- a/integration_tests/commands/resp/append_test.go +++ b/integration_tests/commands/resp/append_test.go @@ -44,7 +44,7 @@ func TestAPPEND(t *testing.T) { { name: "APPEND to key created using LPUSH", commands: []string{"LPUSH m bhima", "APPEND m shankar"}, - expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []string{"DEL m"}, }, { @@ -56,13 +56,13 @@ func TestAPPEND(t *testing.T) { { name: "APPEND to key created using SADD", commands: []string{"SADD key apple", "APPEND key banana"}, - expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []string{"DEL key"}, }, { name: "APPEND to key created using ZADD", commands: []string{"ZADD key 1 one", "APPEND key two"}, - expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []string{"DEL key"}, }, { @@ -94,10 +94,10 @@ func TestAPPEND(t *testing.T) { int64(0), int64(1), int64(1), - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), int64(6), - "WRONGTYPE Operation against a key holding the wrong kind of value", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), + diceerrors.ErrWrongTypeOperation.Error(), }, cleanup: []string{"DEL listKey", "DEL bitKey", "DEL hashKey", "DEL setKey"}, }, @@ -123,7 +123,7 @@ func TestAPPEND(t *testing.T) { }) } - setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value" + setErrorMsg := diceerrors.ErrWrongTypeOperation.Error() ttlTolerance := int64(2) // Set tolerance in seconds for the TTL checks ttlTestCases := []struct { name string diff --git a/integration_tests/commands/resp/bit_test.go b/integration_tests/commands/resp/bit_test.go index 7d7d48212..0127a9926 100644 --- a/integration_tests/commands/resp/bit_test.go +++ b/integration_tests/commands/resp/bit_test.go @@ -753,21 +753,21 @@ func TestBitfield(t *testing.T) { { Name: "BITFIELD on unsupported type of SET", Commands: []string{"SADD bits a b c", "bitfield bits"}, - Expected: []interface{}{int64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{int64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD on unsupported type of JSON", Commands: []string{"json.set bits $ 1", "bitfield bits"}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD on unsupported type of HSET", Commands: []string{"HSET bits a 1", "bitfield bits"}, - Expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, @@ -1001,21 +1001,21 @@ func TestBitfieldRO(t *testing.T) { { Name: "BITFIELD_RO on unsupported type of SET", Commands: []string{"SADD bits a b c", "bitfield_ro bits"}, - Expected: []interface{}{int64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{int64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD_RO on unsupported type of JSON", Commands: []string{"json.set bits $ 1", "bitfield_ro bits"}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD_RO on unsupported type of HSET", Commands: []string{"HSET bits a 1", "bitfield_ro bits"}, - Expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, diff --git a/integration_tests/commands/resp/bloom_test.go b/integration_tests/commands/resp/bloom_test.go index 5af5b3044..8f72cf2e6 100644 --- a/integration_tests/commands/resp/bloom_test.go +++ b/integration_tests/commands/resp/bloom_test.go @@ -185,21 +185,21 @@ func TestBFEdgeCasesAndErrors(t *testing.T) { { name: "BF.RESERVE on a key holding a string value", cmds: []string{"SET foo \"string_value\"", "BF.RESERVE foo 0.001 1000"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, { name: "BF.ADD on a key holding a list", cmds: []string{"LPUSH foo \"item1\"", "BF.ADD foo item2"}, - expect: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, { name: "BF.INFO on a key holding a hash", cmds: []string{"HSET foo field1 value1", "BF.INFO foo"}, - expect: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, diff --git a/integration_tests/commands/resp/check_type_test.go b/integration_tests/commands/resp/check_type_test.go index 80530c77b..079a8c668 100644 --- a/integration_tests/commands/resp/check_type_test.go +++ b/integration_tests/commands/resp/check_type_test.go @@ -12,7 +12,7 @@ func TestErrorsForSetData(t *testing.T) { conn := getLocalConnection() defer conn.Close() - setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value" + setErrorMsg := diceerrors.ErrWrongTypeOperation.Error() testCases := []struct { name string cmd []string diff --git a/integration_tests/commands/resp/deque_test.go b/integration_tests/commands/resp/deque_test.go index db69db3ce..8a3227e2f 100644 --- a/integration_tests/commands/resp/deque_test.go +++ b/integration_tests/commands/resp/deque_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + diceerrors "github.com/dicedb/dice/internal/errors" "github.com/stretchr/testify/assert" ) @@ -468,7 +469,7 @@ func TestLInsert(t *testing.T) { { name: "LINSERT wrong type", cmds: []string{"SET k1 val1", "LINSERT k1 before val1 val2"}, - expect: []any{"OK", "-WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []any{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } @@ -512,7 +513,7 @@ func TestLRange(t *testing.T) { { name: "LRANGE wrong type", cmds: []string{"SET k1 val1", "LRANGE k1 0 100"}, - expect: []any{"OK", "-WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []any{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/getdel_test.go b/integration_tests/commands/resp/getdel_test.go index b92cf7582..c678a6ead 100644 --- a/integration_tests/commands/resp/getdel_test.go +++ b/integration_tests/commands/resp/getdel_test.go @@ -52,13 +52,13 @@ func TestGetDel(t *testing.T) { { name: "GetDel with Set object should return wrong type error", cmds: []string{"SADD myset member1", "GETDEL myset"}, - expect: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { name: "GetDel with JSON object should return wrong type error", cmds: []string{"JSON.SET k $ 1", "GETDEL k", "JSON.GET k"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", "1"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), "1"}, delays: []time.Duration{0, 0, 0}, }, } diff --git a/integration_tests/commands/resp/getex_test.go b/integration_tests/commands/resp/getex_test.go index 94fa5434f..b35e9df37 100644 --- a/integration_tests/commands/resp/getex_test.go +++ b/integration_tests/commands/resp/getex_test.go @@ -122,7 +122,7 @@ func TestGetEx(t *testing.T) { { name: "GetEx with key holding JSON type", commands: []string{"JSON.SET KEY $ \"1\"", "GETEX KEY"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, @@ -130,16 +130,16 @@ func TestGetEx(t *testing.T) { name: "GetEx with key holding JSON type with multiple set commands", commands: []string{"JSON.SET MJSONKEY $ \"{\"a\":2}\"", "GETEX MJSONKEY", "JSON.SET MJSONKEY $.a \"3\"", "GETEX MJSONKEY"}, expected: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), "OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal", "equal", "equal"}, delay: []time.Duration{0, 0, 0, 0}, }, { name: "GetEx with key holding SET type", commands: []string{"SADD SKEY 1 2 3", "GETEX SKEY"}, - expected: []interface{}{int64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(3), diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal", "equal"}, delay: []time.Duration{0, 0}, }, diff --git a/integration_tests/commands/resp/getrange_test.go b/integration_tests/commands/resp/getrange_test.go index 343654f6d..86e6ac22c 100644 --- a/integration_tests/commands/resp/getrange_test.go +++ b/integration_tests/commands/resp/getrange_test.go @@ -62,7 +62,7 @@ func TestGETRANGE(t *testing.T) { { name: "Get range on wrong key type", commands: []string{"LPUSH test3 shankar", "GETRANGE test3 0 7"}, - expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanup: []string{"del test3"}, }, { diff --git a/integration_tests/commands/resp/getset_test.go b/integration_tests/commands/resp/getset_test.go index 8846bae9e..03f69cee9 100644 --- a/integration_tests/commands/resp/getset_test.go +++ b/integration_tests/commands/resp/getset_test.go @@ -38,7 +38,7 @@ func TestGetSet(t *testing.T) { { name: "GETSET error when key exists but does not hold a string value", cmds: []string{"LPUSH k1 \"somevalue\"", "GETSET k1 \"v1\""}, - expect: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0, 0}, }, } diff --git a/integration_tests/commands/resp/hdel_test.go b/integration_tests/commands/resp/hdel_test.go index f931f781a..d93b47956 100644 --- a/integration_tests/commands/resp/hdel_test.go +++ b/integration_tests/commands/resp/hdel_test.go @@ -29,7 +29,7 @@ func TestHDEL(t *testing.T) { }, { commands: []string{"SET k v", "HDEL k f"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hexists_test.go b/integration_tests/commands/resp/hexists_test.go index 65ab8914e..2a5550466 100644 --- a/integration_tests/commands/resp/hexists_test.go +++ b/integration_tests/commands/resp/hexists_test.go @@ -3,6 +3,7 @@ package resp import ( "testing" + diceerrors "github.com/dicedb/dice/internal/errors" "github.com/stretchr/testify/assert" ) @@ -51,7 +52,7 @@ func TestHExists(t *testing.T) { { name: "RESP HEXISTS operation against a key holding the wrong kind of value", commands: []string{"SET key value", "HEXISTS key field"}, - expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hget_test.go b/integration_tests/commands/resp/hget_test.go index 79489550b..06d071814 100644 --- a/integration_tests/commands/resp/hget_test.go +++ b/integration_tests/commands/resp/hget_test.go @@ -36,7 +36,7 @@ func TestHGET(t *testing.T) { }, { commands: []string{"SET key value", "HGET key field"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hgetall_test.go b/integration_tests/commands/resp/hgetall_test.go index c179d9b7e..4148ebe98 100644 --- a/integration_tests/commands/resp/hgetall_test.go +++ b/integration_tests/commands/resp/hgetall_test.go @@ -23,7 +23,7 @@ func TestHGETALL(t *testing.T) { }, { commands: []string{"SET key_hGetAll02 field", "HGETALL key_hGetAll02"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { commands: []string{"HGETALL key_hGetAll03 x", "HGETALL"}, diff --git a/integration_tests/commands/resp/hincrby_test.go b/integration_tests/commands/resp/hincrby_test.go index 01f694a3b..7501ebb3d 100644 --- a/integration_tests/commands/resp/hincrby_test.go +++ b/integration_tests/commands/resp/hincrby_test.go @@ -39,7 +39,7 @@ func TestHINCRBY(t *testing.T) { { name: "HINCRBY on non-hashmap key", cmds: []string{"SET key value", "HINCRBY key value 10"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0, 0}, }, { diff --git a/integration_tests/commands/resp/hincrbyfloat_test.go b/integration_tests/commands/resp/hincrbyfloat_test.go index df16faeb7..e0cd94508 100644 --- a/integration_tests/commands/resp/hincrbyfloat_test.go +++ b/integration_tests/commands/resp/hincrbyfloat_test.go @@ -39,7 +39,7 @@ func TestHINCRBYFLOAT(t *testing.T) { { name: "HINCRBYFLOAT on non-hashmap key", cmds: []string{"SET key value", "HINCRBYFLOAT key value 10"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/resp/hkeys_test.go b/integration_tests/commands/resp/hkeys_test.go index 92597730b..6688bde26 100644 --- a/integration_tests/commands/resp/hkeys_test.go +++ b/integration_tests/commands/resp/hkeys_test.go @@ -3,6 +3,7 @@ package resp import ( "testing" + diceerrors "github.com/dicedb/dice/internal/errors" "github.com/stretchr/testify/assert" ) @@ -24,7 +25,7 @@ func TestHKeys(t *testing.T) { { name: "RESP HKEYS with key containing a non-hash value", commands: []string{"SET key_hkeys02 field1", "HKEYS key_hkeys02"}, - expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "RESP HKEYS with wrong number of arguments", diff --git a/integration_tests/commands/resp/hlen_test.go b/integration_tests/commands/resp/hlen_test.go index eae9b1be8..cbac93c99 100644 --- a/integration_tests/commands/resp/hlen_test.go +++ b/integration_tests/commands/resp/hlen_test.go @@ -34,7 +34,7 @@ func TestHLEN(t *testing.T) { { name: "HLEN with non-hash", cmds: []string{"SET string_key string_value", "HLEN string_key"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/resp/hmget_test.go b/integration_tests/commands/resp/hmget_test.go index ad946e9cf..14b7f495f 100644 --- a/integration_tests/commands/resp/hmget_test.go +++ b/integration_tests/commands/resp/hmget_test.go @@ -35,7 +35,7 @@ func TestHMGET(t *testing.T) { { name: "hmget with wrongtype", commands: []string{"SET key_hmGet1 field", "HMGET key_hmGet1 field"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "wrong number of arguments", diff --git a/integration_tests/commands/resp/hmset_test.go b/integration_tests/commands/resp/hmset_test.go index 44e68d0a6..ee44b6357 100644 --- a/integration_tests/commands/resp/hmset_test.go +++ b/integration_tests/commands/resp/hmset_test.go @@ -1,8 +1,9 @@ package resp import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestHMSET(t *testing.T) { @@ -32,7 +33,7 @@ func TestHMSET(t *testing.T) { }, { commands: []string{"SET k v", "HMSET k f v"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hscan_test.go b/integration_tests/commands/resp/hscan_test.go index d019cb852..51feafb51 100644 --- a/integration_tests/commands/resp/hscan_test.go +++ b/integration_tests/commands/resp/hscan_test.go @@ -35,7 +35,7 @@ func TestHSCAN(t *testing.T) { cmds: []string{"SET string_key string_value", "HSCAN string_key 0"}, expect: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/resp/hset_test.go b/integration_tests/commands/resp/hset_test.go index 272df8889..b07cbb386 100644 --- a/integration_tests/commands/resp/hset_test.go +++ b/integration_tests/commands/resp/hset_test.go @@ -33,7 +33,7 @@ func TestHSET(t *testing.T) { }, { commands: []string{"SET k v", "HSET k f v"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hsetnx_test.go b/integration_tests/commands/resp/hsetnx_test.go index 8e59e3160..ea66f0a28 100644 --- a/integration_tests/commands/resp/hsetnx_test.go +++ b/integration_tests/commands/resp/hsetnx_test.go @@ -25,7 +25,7 @@ func TestHSETNX(t *testing.T) { }, { commands: []string{"SET key_nx_t4 v", "HSETNX key_nx_t4 f v"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/hstrlen_test.go b/integration_tests/commands/resp/hstrlen_test.go index 28c51bf13..6843d3728 100644 --- a/integration_tests/commands/resp/hstrlen_test.go +++ b/integration_tests/commands/resp/hstrlen_test.go @@ -53,7 +53,7 @@ func TestHSTRLEN(t *testing.T) { { name: "HSTRLEN with non-hash", cmds: []string{"SET string_key string_value", "HSTRLEN string_key field"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/resp/hvals_test.go b/integration_tests/commands/resp/hvals_test.go index ca0a10dfe..80341def9 100644 --- a/integration_tests/commands/resp/hvals_test.go +++ b/integration_tests/commands/resp/hvals_test.go @@ -3,6 +3,7 @@ package resp import ( "testing" + diceerrors "github.com/dicedb/dice/internal/errors" "github.com/stretchr/testify/assert" ) @@ -24,7 +25,7 @@ func TestHVals(t *testing.T) { { name: "HVALS on wrong key type", commands: []string{"SET hvalsKey02 field", "HVALS hvalsKey02"}, - expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "HVALS with wrong number of arguments", diff --git a/integration_tests/commands/resp/json_test.go b/integration_tests/commands/resp/json_test.go index c2c498a32..7774c6637 100644 --- a/integration_tests/commands/resp/json_test.go +++ b/integration_tests/commands/resp/json_test.go @@ -148,7 +148,7 @@ func TestJSONOperations(t *testing.T) { name: "Set Non-JSON Value", setCmd: `SET nonJson "not a json"`, getCmd: `JSON.GET nonJson`, - expected: "WRONGTYPE Operation against a key holding the wrong kind of value", + expected: diceerrors.ErrWrongTypeOperation.Error(), }, { name: "Set Empty JSON Object", @@ -1231,7 +1231,7 @@ func TestJsonObjLen(t *testing.T) { { name: "JSON.OBJLEN with legacy path - inner existent path with nonJSON object", commands: []string{"json.set obj $ " + c, "json.objlen obj .name"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "JSON.OBJLEN with legacy path - inner existent path recursive object", diff --git a/integration_tests/commands/resp/set_data_cmd_test.go b/integration_tests/commands/resp/set_data_cmd_test.go index 5efb0bf75..751935b2d 100644 --- a/integration_tests/commands/resp/set_data_cmd_test.go +++ b/integration_tests/commands/resp/set_data_cmd_test.go @@ -62,7 +62,7 @@ func TestSetDataCommand(t *testing.T) { { name: "SADD Wrong Key Value Type", cmd: []string{"SET foo bar", "SADD foo baz"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, @@ -91,7 +91,7 @@ func TestSetDataCommand(t *testing.T) { { name: "SADD & SCARD with wrong key type", cmd: []string{"SET foo bar", "SCARD foo"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, @@ -113,7 +113,7 @@ func TestSetDataCommand(t *testing.T) { { name: "SADD & SMEMBERS with wrong key type", cmd: []string{"SET foo bar", "SMEMBERS foo"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, @@ -135,7 +135,7 @@ func TestSetDataCommand(t *testing.T) { { name: "SADD & SREM with wrong key type", cmd: []string{"SET foo bar", "SREM foo bar"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, assertType: []string{"equal", "equal"}, delay: []time.Duration{0, 0}, }, diff --git a/integration_tests/commands/resp/set_test.go b/integration_tests/commands/resp/set_test.go index dc07883f9..c098f0b54 100644 --- a/integration_tests/commands/resp/set_test.go +++ b/integration_tests/commands/resp/set_test.go @@ -133,7 +133,7 @@ func TestSetWithOptions(t *testing.T) { { name: "GET with wrong type of value", commands: []string{"sadd k v", "SET k vv GET"}, - expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{int64(1), diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/resp/zcard_test.go b/integration_tests/commands/resp/zcard_test.go index b799ae170..79332569a 100644 --- a/integration_tests/commands/resp/zcard_test.go +++ b/integration_tests/commands/resp/zcard_test.go @@ -28,7 +28,7 @@ func TestZCARD(t *testing.T) { name: "ZCARD with wrong type of key", cmds: []string{"SET string_key string_value", "ZCARD string_key"}, expect: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/resp/zpopmax_test.go b/integration_tests/commands/resp/zpopmax_test.go index f89389259..0086862de 100644 --- a/integration_tests/commands/resp/zpopmax_test.go +++ b/integration_tests/commands/resp/zpopmax_test.go @@ -19,7 +19,7 @@ func TestZPOPMax(t *testing.T) { { name: "ZPOPMAX with wrong type of key with/without count argument", commands: []string{"SET stringkey string_value", "ZPOPMAX stringkey"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "ZPOPMAX on existing key (without count argument)", diff --git a/integration_tests/commands/resp/zrem_test.go b/integration_tests/commands/resp/zrem_test.go index 7ff8956bb..fde9e3b0f 100644 --- a/integration_tests/commands/resp/zrem_test.go +++ b/integration_tests/commands/resp/zrem_test.go @@ -28,7 +28,7 @@ func TestZREM(t *testing.T) { name: "ZREM with wrong type of key", cmds: []string{"SET string_key string_value", "ZREM string_key string_value"}, expect: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/resp/zset_test.go b/integration_tests/commands/resp/zset_test.go index 60e3b7196..cff47ac92 100644 --- a/integration_tests/commands/resp/zset_test.go +++ b/integration_tests/commands/resp/zset_test.go @@ -19,7 +19,7 @@ func TestZPOPMIN(t *testing.T) { { name: "ZPOPMIN with wrong type of key with/without count argument", commands: []string{"SET stringkey string_value", "ZPOPMIN stringkey", "DEL stringkey"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", int64(1)}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), int64(1)}, }, { name: "ZPOPMIN on existing key (without count argument)", diff --git a/integration_tests/commands/websocket/append_test.go b/integration_tests/commands/websocket/append_test.go index a04e4d1d3..469e51a3e 100644 --- a/integration_tests/commands/websocket/append_test.go +++ b/integration_tests/commands/websocket/append_test.go @@ -36,7 +36,7 @@ func TestAppend(t *testing.T) { { name: "APPEND to key created using LPUSH", commands: []string{"LPUSH z bhima", "APPEND z shankar"}, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanupKey: "z", }, { @@ -48,7 +48,7 @@ func TestAppend(t *testing.T) { { name: "APPEND to key created using ZADD", commands: []string{"ZADD key 1 one", "APPEND key two"}, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanupKey: "key", }, { @@ -86,10 +86,10 @@ func TestAppend(t *testing.T) { float64(0), float64(1), float64(1), - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), float64(6), - "WRONGTYPE Operation against a key holding the wrong kind of value", - "WRONGTYPE Operation against a key holding the wrong kind of value", + diceerrors.ErrWrongTypeOperation.Error(), + diceerrors.ErrWrongTypeOperation.Error(), }, cleanupKey: "listKey", }, diff --git a/integration_tests/commands/websocket/bit_test.go b/integration_tests/commands/websocket/bit_test.go index f2a97e5be..7cc36f0d1 100644 --- a/integration_tests/commands/websocket/bit_test.go +++ b/integration_tests/commands/websocket/bit_test.go @@ -761,21 +761,21 @@ func TestBitfield(t *testing.T) { { Name: "BITFIELD on unsupported type of SET", Commands: []string{"SADD bits a b c", "bitfield bits"}, - Expected: []interface{}{float64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD on unsupported type of JSON", Commands: []string{"json.set bits $ 1", "bitfield bits"}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD on unsupported type of HSET", Commands: []string{"HSET bits a 1", "bitfield bits"}, - Expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, @@ -1011,21 +1011,21 @@ func TestBitfieldRO(t *testing.T) { { Name: "BITFIELD_RO on unsupported type of SET", Commands: []string{"SADD bits a b c", "bitfield_ro bits"}, - Expected: []interface{}{float64(3), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(3), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD_RO on unsupported type of JSON", Commands: []string{"json.set bits $ 1", "bitfield_ro bits"}, - Expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, { Name: "BITFIELD_RO on unsupported type of HSET", Commands: []string{"HSET bits a 1", "bitfield_ro bits"}, - Expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + Expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, Delay: []time.Duration{0, 0}, CleanUp: []string{"DEL bits"}, }, diff --git a/integration_tests/commands/websocket/bloom_test.go b/integration_tests/commands/websocket/bloom_test.go index d8c9222ca..a91e031ad 100644 --- a/integration_tests/commands/websocket/bloom_test.go +++ b/integration_tests/commands/websocket/bloom_test.go @@ -176,21 +176,21 @@ func TestBFEdgeCasesAndErrors(t *testing.T) { { name: "BF.RESERVE on a key holding a string value", cmds: []string{"SET foo \"string_value\"", "BF.RESERVE foo 0.001 1000"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, { name: "BF.ADD on a key holding a list", cmds: []string{"LPUSH foo \"item1\"", "BF.ADD foo item2"}, - expect: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, { name: "BF.INFO on a key holding a hash", cmds: []string{"HSET foo field1 value1", "BF.INFO foo"}, - expect: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, cleanUp: []string{"del foo"}, }, diff --git a/integration_tests/commands/websocket/getrange_test.go b/integration_tests/commands/websocket/getrange_test.go index 136d0d0cc..be3753701 100644 --- a/integration_tests/commands/websocket/getrange_test.go +++ b/integration_tests/commands/websocket/getrange_test.go @@ -56,7 +56,7 @@ func TestGETRANGE(t *testing.T) { { name: "Get range on wrong key type", commands: []string{"LPUSH test3 shankar", "GETRANGE test3 0 7"}, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, cleanupKey: "test3", }, { diff --git a/integration_tests/commands/websocket/hdel_test.go b/integration_tests/commands/websocket/hdel_test.go index 92ca4e481..04bd41631 100644 --- a/integration_tests/commands/websocket/hdel_test.go +++ b/integration_tests/commands/websocket/hdel_test.go @@ -80,7 +80,7 @@ func TestHDEL(t *testing.T) { "SET string_key value", "HDEL string_key field", }, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/websocket/hget_test.go b/integration_tests/commands/websocket/hget_test.go index 36aeb2feb..25404d2da 100644 --- a/integration_tests/commands/websocket/hget_test.go +++ b/integration_tests/commands/websocket/hget_test.go @@ -69,7 +69,7 @@ func TestHGET(t *testing.T) { "SET string_key value", "HGET string_key field", }, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/websocket/hincrby_test.go b/integration_tests/commands/websocket/hincrby_test.go index 669ab8973..b3061c5dd 100644 --- a/integration_tests/commands/websocket/hincrby_test.go +++ b/integration_tests/commands/websocket/hincrby_test.go @@ -42,7 +42,7 @@ func TestHINCRBY(t *testing.T) { { name: "HINCRBY on non-hashmap key", cmds: []string{"SET key value", "HINCRBY key value 10"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0, 0}, }, { diff --git a/integration_tests/commands/websocket/hincrbyfloat_test.go b/integration_tests/commands/websocket/hincrbyfloat_test.go index a7f76544e..b0a4ca2f9 100644 --- a/integration_tests/commands/websocket/hincrbyfloat_test.go +++ b/integration_tests/commands/websocket/hincrbyfloat_test.go @@ -41,7 +41,7 @@ func TestHINCRBYFLOAT(t *testing.T) { { name: "HINCRBYFLOAT on non-hashmap key", cmds: []string{"SET key value", "HINCRBYFLOAT key value 10"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/websocket/hlen_test.go b/integration_tests/commands/websocket/hlen_test.go index 093a89dd6..39a1d2251 100644 --- a/integration_tests/commands/websocket/hlen_test.go +++ b/integration_tests/commands/websocket/hlen_test.go @@ -37,7 +37,7 @@ func TestHLEN(t *testing.T) { { name: "HLEN with non-hash", cmds: []string{"SET string_key string_value", "HLEN string_key"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/websocket/hscan_test.go b/integration_tests/commands/websocket/hscan_test.go index d9f1f8ca2..c679d72f1 100644 --- a/integration_tests/commands/websocket/hscan_test.go +++ b/integration_tests/commands/websocket/hscan_test.go @@ -43,7 +43,7 @@ func TestHSCAN(t *testing.T) { { name: "HSCAN with non-hash", cmds: []string{"SET string_key string_value", "HSCAN string_key 0"}, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/websocket/hset_test.go b/integration_tests/commands/websocket/hset_test.go index bc2764de2..407e354f2 100644 --- a/integration_tests/commands/websocket/hset_test.go +++ b/integration_tests/commands/websocket/hset_test.go @@ -68,7 +68,7 @@ func TestHSET(t *testing.T) { "SET string_key value", "HSET string_key field value", }, - expect: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expect: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, } diff --git a/integration_tests/commands/websocket/json_test.go b/integration_tests/commands/websocket/json_test.go index 71b85a079..41e66c513 100644 --- a/integration_tests/commands/websocket/json_test.go +++ b/integration_tests/commands/websocket/json_test.go @@ -348,7 +348,7 @@ func TestJsonObjLen(t *testing.T) { { name: "JSON.OBJLEN with legacy path - inner existent path with nonJSON object", commands: []string{"json.set obj $ " + c, "json.objlen obj .name"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error()}, }, { name: "JSON.OBJLEN with legacy path - inner existent path recursive object", diff --git a/integration_tests/commands/websocket/set_test.go b/integration_tests/commands/websocket/set_test.go index 8dac72f15..40b223761 100644 --- a/integration_tests/commands/websocket/set_test.go +++ b/integration_tests/commands/websocket/set_test.go @@ -134,7 +134,7 @@ func TestSetWithOptions(t *testing.T) { { name: "GET with wrong type of value", commands: []string{"sadd k v", "SET k vv GET"}, - expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"}, + expected: []interface{}{float64(1), diceerrors.ErrWrongTypeOperation.Error()}, }, } diff --git a/integration_tests/commands/websocket/zcard_test.go b/integration_tests/commands/websocket/zcard_test.go index 34561134b..c6bd649d9 100644 --- a/integration_tests/commands/websocket/zcard_test.go +++ b/integration_tests/commands/websocket/zcard_test.go @@ -32,7 +32,7 @@ func TestZCARD(t *testing.T) { name: "ZCARD with wrong type of key", cmds: []string{"SET string_key string_value", "ZCARD string_key"}, expect: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/websocket/zpopmax_test.go b/integration_tests/commands/websocket/zpopmax_test.go index f91557601..f1db980a4 100644 --- a/integration_tests/commands/websocket/zpopmax_test.go +++ b/integration_tests/commands/websocket/zpopmax_test.go @@ -17,7 +17,7 @@ func TestZPOPMAX(t *testing.T) { { name: "ZPOPMAX with wrong type of key with/without count argument", commands: []string{"SET stringkey string_value", "ZPOPMAX stringkey", "ZCOUNT sortedSet 1 10"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", float64(0)}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), float64(0)}, }, { name: "ZPOPMAX on existing key (without count argument)", diff --git a/integration_tests/commands/websocket/zrem_test.go b/integration_tests/commands/websocket/zrem_test.go index ef8f9e3ae..40b0a51b3 100644 --- a/integration_tests/commands/websocket/zrem_test.go +++ b/integration_tests/commands/websocket/zrem_test.go @@ -33,7 +33,7 @@ func TestZREM(t *testing.T) { name: "ZREM with wrong type of key", cmds: []string{"SET string_key string_value", "ZREM string_key string_value"}, expect: []interface{}{"OK", - "WRONGTYPE Operation against a key holding the wrong kind of value"}, + diceerrors.ErrWrongTypeOperation.Error()}, delays: []time.Duration{0, 0}, }, { diff --git a/integration_tests/commands/websocket/zset_test.go b/integration_tests/commands/websocket/zset_test.go index 30c4bfd56..182888964 100644 --- a/integration_tests/commands/websocket/zset_test.go +++ b/integration_tests/commands/websocket/zset_test.go @@ -18,7 +18,7 @@ func TestZPOPMIN(t *testing.T) { { name: "ZPOPMIN with wrong type of key with/without count argument", commands: []string{"SET stringkey string_value", "ZPOPMIN stringkey", "DEL stringkey"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", float64(1)}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), float64(1)}, }, { name: "ZPOPMIN on existing key (without count argument)", @@ -88,7 +88,7 @@ func TestZCOUNT(t *testing.T) { { name: "ZCOUNT on key with wrong type", commands: []string{"SET stringkey string_value", "ZCOUNT stringkey 0 10", "DEL stringkey"}, - expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value", float64(1)}, + expected: []interface{}{"OK", diceerrors.ErrWrongTypeOperation.Error(), float64(1)}, }, { name: "ZCOUNT on existing key with valid range", diff --git a/internal/errors/errors.go b/internal/errors/errors.go index 306b94d3c..803bcd330 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -15,8 +15,8 @@ const ( ValOutOfRangeErr = "value is out of range" IncrDecrOverflowErr = "increment or decrement would overflow" NoKeyErr = "no such key" - ErrDefault = "-ERR %s" - WrongTypeErr = "-WRONGTYPE Operation against a key holding the wrong kind of value" + ErrDefault = "ERR %s" + WrongTypeErr = "WRONGTYPE Operation against a key holding the wrong kind of value" WrongTypeHllErr = "-WRONGTYPE Key is not a valid HyperLogLog string value." InvalidHllErr = "-INVALIDOBJ Corrupted HLL object detected" IOThreadNotFoundErr = "io-thread with ID %s not found" diff --git a/internal/eval/eval.go b/internal/eval/eval.go index 0b28e079d..67739a65e 100644 --- a/internal/eval/eval.go +++ b/internal/eval/eval.go @@ -693,7 +693,7 @@ func evalSINTER(args []string, store *dstore.Store) []byte { // If the object exists, check if it is a set object. if err := object.AssertType(obj.Type, object.ObjTypeSet); err != nil { - return diceerrors.NewErrWithFormattedMessage(diceerrors.WrongTypeErr) + return clientio.Encode(diceerrors.ErrWrongTypeOperation, false) } // Get the set object. diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index f1a629a6e..e413cffdc 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -146,10 +146,10 @@ func TestEval(t *testing.T) { func testEvalPING(t *testing.T, store *dstore.Store) { tests := map[string]evalTestCase{ - "nil value": {input: nil, output: []byte("+PONG\r\n")}, - "empty args": {input: []string{}, output: []byte("+PONG\r\n")}, - "one value": {input: []string{"HEY"}, output: []byte("$3\r\nHEY\r\n")}, - "more than one values": {input: []string{"HEY", "HELLO"}, output: []byte("-ERR wrong number of arguments for 'ping' command\r\n")}, + "PING: nil value": {input: nil, output: []byte("+PONG\r\n")}, + "PING: empty args": {input: []string{}, output: []byte("+PONG\r\n")}, + "PING: one value": {input: []string{"HEY"}, output: []byte("$3\r\nHEY\r\n")}, + "PING: more than one values": {input: []string{"HEY", "HELLO"}, output: []byte(diceerrors.ErrWrongArgumentCount("ping").Error())}, } runEvalTests(t, tests, evalPING, store) @@ -157,10 +157,10 @@ func testEvalPING(t *testing.T, store *dstore.Store) { func testEvalECHO(t *testing.T, store *dstore.Store) { tests := map[string]evalTestCase{ - "nil value": {input: nil, output: []byte("-ERR wrong number of arguments for 'echo' command\r\n")}, - "empty args": {input: []string{}, output: []byte("-ERR wrong number of arguments for 'echo' command\r\n")}, - "one value": {input: []string{"HEY"}, output: []byte("$3\r\nHEY\r\n")}, - "more than one values": {input: []string{"HEY", "HELLO"}, output: []byte("-ERR wrong number of arguments for 'echo' command\r\n")}, + "ECHO: nil value": {input: nil, output: []byte(diceerrors.ErrWrongArgumentCount("echo").Error())}, + "ECHO: empty args": {input: []string{}, output: []byte(diceerrors.ErrWrongArgumentCount("echo").Error())}, + "ECHO: one value": {input: []string{"HEY"}, output: []byte("$3\r\nHEY\r\n")}, + "ECHO: more than one values": {input: []string{"HEY", "HELLO"}, output: []byte(diceerrors.ErrWrongArgumentCount("echo").Error())}, } runEvalTests(t, tests, evalECHO, store) @@ -178,10 +178,10 @@ func testEvalHELLO(t *testing.T, store *dstore.Store) { } tests := map[string]evalTestCase{ - "nil value": {input: nil, output: clientio.Encode(resp, false)}, - "empty args": {input: []string{}, output: clientio.Encode(resp, false)}, - "one value": {input: []string{"HEY"}, output: clientio.Encode(resp, false)}, - "more than one values": {input: []string{"HEY", "HELLO"}, output: []byte("-ERR wrong number of arguments for 'hello' command\r\n")}, + "HELLO: nil value": {input: nil, output: clientio.Encode(resp, false)}, + "HELLO: empty args": {input: []string{}, output: clientio.Encode(resp, false)}, + "HELLO: one value": {input: []string{"HEY"}, output: clientio.Encode(resp, false)}, + "HELLO: more than one values": {input: []string{"HEY", "HELLO"}, output: []byte(diceerrors.ErrWrongArgumentCount("hello").Error())}, } runEvalTests(t, tests, evalHELLO, store) @@ -2900,7 +2900,7 @@ func testEvalDbsize(t *testing.T, store *dstore.Store) { tests := map[string]evalTestCase{ "DBSIZE command with invalid no of args": { input: []string{"INVALID_ARG"}, - output: []byte("-ERR wrong number of arguments for 'dbsize' command\r\n"), + output: []byte(diceerrors.ErrWrongArgumentCount("dbsize").Error()), }, "no key in db": { input: nil, @@ -3949,12 +3949,12 @@ func testEvalLPUSH(t *testing.T, store *dstore.Store) { input: []string{"KEY1"}, migratedOutput: EvalResponse{Result: nil, Error: errors.New("ERR wrong number of arguments for 'lpush' command")}, }, - "key with different type": { + "LPUSH: key with different type": { setup: func() { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "value_1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, "key does not exist": { input: []string{"NONEXISTENT_KEY", "value_1"}, @@ -3984,12 +3984,12 @@ func testEvalRPUSH(t *testing.T, store *dstore.Store) { input: []string{"KEY1"}, migratedOutput: EvalResponse{Result: nil, Error: errors.New("ERR wrong number of arguments for 'rpush' command")}, }, - "key with different type": { + "RPUSH: key with different type": { setup: func() { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "value_1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, "key does not exist": { input: []string{"NONEXISTENT_KEY", "value_1"}, @@ -4027,12 +4027,12 @@ func testEvalLPOP(t *testing.T, store *dstore.Store) { input: []string{"k", "-1"}, migratedOutput: EvalResponse{Result: nil, Error: errors.New("ERR value is not an integer or out of range")}, }, - "key with different type": { + "LPOP: key with different type": { setup: func() { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, "key does not exist": { input: []string{"NONEXISTENT_KEY"}, @@ -4104,7 +4104,7 @@ func testEvalRPOP(t *testing.T, store *dstore.Store) { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, "key does not exist": { input: []string{"NONEXISTENT_KEY"}, @@ -4159,7 +4159,7 @@ func testEvalLLEN(t *testing.T, store *dstore.Store) { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, } @@ -4345,7 +4345,7 @@ func runEvalTests(t *testing.T, tests map[string]evalTestCase, evalFunc func([]s if tc.validator != nil { tc.validator(output) } else { - assert.Equal(t, string(tc.output), string(output)) + assert.Equal(t, strings.TrimSpace(string(tc.output)), strings.TrimSpace(string(output))) } }) } @@ -4638,7 +4638,7 @@ func testEvalHKEYS(t *testing.T, store *dstore.Store) { evalSET([]string{"string_key", "string_value"}, store) }, input: []string{"string_key"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("ERR -WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "HKEYS key exists and is a hash", @@ -8108,7 +8108,7 @@ func testEvalDUMP(t *testing.T, store *dstore.Store) { input: []string{"INTEGER_KEY"}, migratedOutput: EvalResponse{ Result: "CQUAAAAAAAAACv9+l81XgsShqw==", - Error: nil, + Error: nil, }, }, "dump expired key": { @@ -8328,7 +8328,7 @@ func testEvalGEODIST(t *testing.T, store *dstore.Store) { func testEvalSINTER(t *testing.T, store *dstore.Store) { tests := map[string]evalTestCase{ - "intersection of two sets": { + "SINTER: intersection of two sets": { setup: func() { evalSADD([]string{"set1", "a", "b", "c"}, store) evalSADD([]string{"set2", "c", "d", "e"}, store) @@ -8336,7 +8336,7 @@ func testEvalSINTER(t *testing.T, store *dstore.Store) { input: []string{"set1", "set2"}, output: clientio.Encode([]string{"c"}, false), }, - "intersection of three sets": { + "SINTER: intersection of three sets": { setup: func() { evalSADD([]string{"set1", "a", "b", "c"}, store) evalSADD([]string{"set2", "b", "c", "d"}, store) @@ -8345,29 +8345,29 @@ func testEvalSINTER(t *testing.T, store *dstore.Store) { input: []string{"set1", "set2", "set3"}, output: clientio.Encode([]string{"c"}, false), }, - "intersection with single set": { + "SINTER: intersection with single set": { setup: func() { evalSADD([]string{"set1", "a"}, store) }, input: []string{"set1"}, output: clientio.Encode([]string{"a"}, false), }, - "intersection with a non-existent key": { + "SINTER: intersection with a non-existent key": { setup: func() { evalSADD([]string{"set1", "a", "b", "c"}, store) }, input: []string{"set1", "nonexistent"}, output: clientio.Encode([]string{}, false), }, - "intersection with wrong type": { + "SINTER: intersection with wrong type": { setup: func() { evalSADD([]string{"set1", "a", "b", "c"}, store) store.Put("string", &object.Obj{Value: "string", Type: object.ObjTypeString}) }, input: []string{"set1", "string"}, - output: []byte("-WRONGTYPE Operation against a key holding the wrong kind of value\r\n"), + output: clientio.Encode(diceerrors.ErrWrongTypeOperation, false), }, - "no arguments": { + "SINTER: no arguments": { input: []string{}, output: diceerrors.NewErrArity("SINTER"), }, @@ -8651,7 +8651,7 @@ func testEvalINCR(t *testing.T, store *dstore.Store) { evalSADD([]string{"SET1", "1", "2", "3"}, store) }, input: []string{"SET1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "INCR key holding MAP type", @@ -8659,7 +8659,7 @@ func testEvalINCR(t *testing.T, store *dstore.Store) { evalHSET([]string{"MAP1", "a", "1", "b", "2", "c", "3"}, store) }, input: []string{"MAP1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "INCR More than one args passed", @@ -8738,7 +8738,7 @@ func testEvalINCRBY(t *testing.T, store *dstore.Store) { evalSADD([]string{"SET1", "1", "2", "3"}, store) }, input: []string{"SET1", "2"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "INCRBY key holding MAP type", @@ -8746,7 +8746,7 @@ func testEvalINCRBY(t *testing.T, store *dstore.Store) { evalHSET([]string{"MAP1", "a", "1", "b", "2", "c", "3"}, store) }, input: []string{"MAP1", "2"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "INCRBY Wrong number of args passed", @@ -8825,7 +8825,7 @@ func testEvalDECR(t *testing.T, store *dstore.Store) { evalSADD([]string{"SET1", "1", "2", "3"}, store) }, input: []string{"SET1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "DECR key holding MAP type", @@ -8833,7 +8833,7 @@ func testEvalDECR(t *testing.T, store *dstore.Store) { evalHSET([]string{"MAP1", "a", "1", "b", "2", "c", "3"}, store) }, input: []string{"MAP1"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "DECR More than one args passed", @@ -8912,7 +8912,7 @@ func testEvalDECRBY(t *testing.T, store *dstore.Store) { evalSADD([]string{"SET1", "1", "2", "3"}, store) }, input: []string{"SET1", "2"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "DECRBY key holding MAP type", @@ -8920,7 +8920,7 @@ func testEvalDECRBY(t *testing.T, store *dstore.Store) { evalHSET([]string{"MAP1", "a", "1", "b", "2", "c", "3"}, store) }, input: []string{"MAP1", "2"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, { name: "DECRBY Wrong number of args passed", @@ -9171,7 +9171,7 @@ func testEvalLINSERT(t *testing.T, store *dstore.Store) { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "before", "mock_value", "element"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("-WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, } runMigratedEvalTests(t, tests, evalLINSERT, store) @@ -9212,12 +9212,12 @@ func testEvalLRANGE(t *testing.T, store *dstore.Store) { input: []string{"EXISTING_KEY", "0", "5"}, migratedOutput: EvalResponse{Result: []string{"before_value", "pivot_value", "after_value"}, Error: nil}, }, - "key with different type": { + "LRANGE key with different type": { setup: func() { evalSET([]string{"EXISTING_KEY", "mock_value"}, store) }, input: []string{"EXISTING_KEY", "0", "4"}, - migratedOutput: EvalResponse{Result: nil, Error: errors.New("-WRONGTYPE Operation against a key holding the wrong kind of value")}, + migratedOutput: EvalResponse{Result: nil, Error: diceerrors.ErrWrongTypeOperation}, }, } runMigratedEvalTests(t, tests, evalLRANGE, store) diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index c80ad9d63..dd9e28efe 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -541,7 +541,7 @@ func evalHKEYS(args []string, store *dstore.Store) *EvalResponse { if obj != nil { if err := object.AssertType(obj.Type, object.ObjTypeHashMap); err != nil { return &EvalResponse{ - Error: diceerrors.ErrGeneral(diceerrors.WrongTypeErr), + Error: diceerrors.ErrWrongTypeOperation, Result: nil, } } diff --git a/internal/object/typeencoding.go b/internal/object/typeencoding.go index 8934fe710..8111683b2 100644 --- a/internal/object/typeencoding.go +++ b/internal/object/typeencoding.go @@ -1,14 +1,12 @@ package object import ( - "errors" - diceerrors "github.com/dicedb/dice/internal/errors" ) func AssertTypeWithError(te, t ObjectType) error { if te != t { - return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") + return diceerrors.ErrWrongTypeOperation } return nil }