Skip to content

Commit

Permalink
Adding a wrong type error message when performing a bloom operation o…
Browse files Browse the repository at this point in the history
…n a non bloom key (#30)

Signed-off-by: zackcam <[email protected]>
  • Loading branch information
zackcam authored Dec 6, 2024
1 parent f10a4e5 commit eaa218f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/bloom/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn bloom_filter_add_value(
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
// Skip bloom filter size validation on replicated cmds.
Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn bloom_filter_exists(
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
if !multi {
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn bloom_filter_card(ctx: &Context, input_args: &[ValkeyString]) -> ValkeyRe
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
match value {
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn bloom_filter_reserve(ctx: &Context, input_args: &[ValkeyString]) -> Valke
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
match value {
Expand Down Expand Up @@ -404,7 +404,7 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &[ValkeyString]) -> Valkey
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
// Skip bloom filter size validation on replicated cmds.
Expand Down Expand Up @@ -472,7 +472,7 @@ pub fn bloom_filter_info(ctx: &Context, input_args: &[ValkeyString]) -> ValkeyRe
let value = match filter_key.get_value::<BloomFilterType>(&BLOOM_FILTER_TYPE) {
Ok(v) => v,
Err(_) => {
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
match value {
Expand Down Expand Up @@ -534,7 +534,7 @@ pub fn bloom_filter_load(ctx: &Context, input_args: &[ValkeyString]) -> ValkeyRe
Ok(v) => v,
Err(_) => {
// error
return Err(ValkeyError::Str(utils::ERROR));
return Err(ValkeyError::WrongType);
}
};
match filter {
Expand Down
25 changes: 25 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,28 @@ def test_debug_cmd(self):
assert madd_scenario_object_digest != madd_default_object_digest
else:
madd_scenario_object_digest == madd_default_object_digest

def test_bloom_wrong_type(self):
# List of all bloom commands
bloom_commands = [
'BF.ADD key item',
'BF.EXISTS key item',
'BF.MADD key item1 item2 item3',
'BF.MEXISTS key item2 item3 item4',
'BF.INSERT key ITEMS item',
'BF.INFO key filters',
'BF.CARD key',
'BF.RESERVE key 0.01 1000',
]
client = self.server.get_new_client()
# Set the key we try to perform bloom commands on
client.execute_command("set key value")
# Run each command and check we get the correct error returned
for cmd in bloom_commands:
cmd_name = cmd.split()[0]
try:
result = client.execute_command(cmd)
assert False, f"{cmd_name} on existing non bloom object should fail, instead: {result}"
except Exception as e:

assert str(e) == f"WRONGTYPE Operation against a key holding the wrong kind of value"

0 comments on commit eaa218f

Please sign in to comment.