Skip to content

Move to RedisString #394

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

Closed
wants to merge 7 commits into from
Closed

Move to RedisString #394

wants to merge 7 commits into from

Conversation

gkorland
Copy link
Contributor

No description provided.

@gkorland gkorland requested review from gavrie and oshadmi June 16, 2021 06:38
@gkorland gkorland marked this pull request as ready for review June 21, 2021 17:10
format = Format::from_str(args.next_string()?.as_str())?;
}
_ => break,
_ => break, // TODO shoudl return an error??
Copy link
Contributor

Choose a reason for hiding this comment

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

It probably should.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Before commit 89b8a95 there seems to have been an error report Err(RedisError::Str("ERR syntax error"))

{
if !value.is_array() {
return Err(err_json(value, "array"));
}

let mut items: Vec<Value> = args
.map(|json| serde_json::from_str(&json))
.map(|json| serde_json::from_str(&json.into_string_lossy()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a lossy conversion what we want here? I know the Redis way is not to return errors, but can't this cause silent data corruption in case the input is not valid UTF-8? JSON should always be valid UTF-8.

format = Format::from_str(args.next_string()?.as_str())?;
}
_ => break,
_ => break, // TODO shoudl return an error??
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before commit 89b8a95 there seems to have been an error report Err(RedisError::Str("ERR syntax error"))

JSONApiKey::new_from_key(key)
}

pub fn new_from_str(
ctx: *mut rawmod::RedisModuleCtx,
path: *const c_char,
) -> Result<JSONApiKey<'a>, RedisError> {
let ctx = Context::new(ctx);
let path = unsafe { CStr::from_ptr(path).to_str().unwrap() };
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line not from this PR, but still would like to raise that since it is also related to UFT-8 and lossy conversion vs. error handling mentioned in this comment
let path = unsafe { CStr::from_ptr(path).to_str().unwrap() };
This would panic if invalid UTF-8 is passed here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since c_api.rs currently has no error reporting capability, we should detect conversion failure and the caller should return null on failure (assuming invalid UFT-8 can arrive from redis/from callers of new_from_str)

@gkorland gkorland closed this Jul 7, 2021
@gkorland gkorland deleted the feature-redisstring branch July 8, 2021 06:52
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.

4 participants