Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Commit 609cc68

Browse files
committed
return error on wrong type
1 parent cf410d7 commit 609cc68

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/redisjson.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ impl RedisJSON {
6161
}
6262

6363
pub fn str_len(&self, path: &str) -> Result<usize, Error> {
64-
let s = match self.get_doc(path)? {
65-
Some(doc) => doc.as_str().map_or(0, |d| d.len()),
66-
None => 0 // path not found
67-
};
68-
Ok(s)
64+
match self.get_doc(path)? {
65+
Some(doc) => {
66+
match doc.as_str() {
67+
Some(s) => Ok(s.len()),
68+
None => Err(Error{msg: "ERR wrong type of path value".to_string()})
69+
}
70+
}
71+
None => Ok(0) // path not found
72+
}
6973
}
7074

7175
pub fn get_doc(&self, path: &str) -> Result<Option<&Value>, Error> {

0 commit comments

Comments
 (0)