Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a wrong type error message when performing a bloom operation on a non bloom key #30

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

zackcam
Copy link
Contributor

@zackcam zackcam commented Dec 6, 2024

Updated the error on the get_value return to be a WRONG_TYPE_ERROR. Added a test as well checking this happens and the error message is correct for each bloom command.

@@ -32,7 +32,7 @@ pub const ENCODE_BLOOM_FILTER_FAILED: &str = "ERR encode bloom filter failed.";
pub const DECODE_BLOOM_FILTER_FAILED: &str = "ERR decode bloom filter failed.";
pub const DECODE_UNSUPPORTED_VERSION: &str =
"ERR decode bloom filter failed. Unsupported version.";

pub const WRONG_TYPE_ERROR: &str = "WRONGTYPE Not a BloomFilter key";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check what message this returns? Maybe we can use this

https://docs.rs/valkey-module/latest/src/valkey_module/rediserror.rs.html#11

@@ -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(_) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best practice is to handle every case in a match. I understand that the SDK does not make this easy for us because they return a specific string message when an ENUM would have made matching easier.

In the future, if it is possible to update the SDK, we should be able to update our handling to make it stricter.

https://github.com/valkey-io/valkeymodule-rs/blob/0a1fb4e8e9b5cc3e26d8fcdbab0857c8bfd87f33/src/key.rs#L678

@KarthikSubbarao KarthikSubbarao merged commit eaa218f into valkey-io:unstable Dec 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants