forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
74 lines (63 loc) · 1.67 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use jsonpath_lib::select::JsonPathError;
use redis_module::RedisError;
use std::num::ParseIntError;
#[derive(Debug)]
pub struct Error {
pub msg: String,
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error { msg: e }
}
}
impl From<redis_module::error::GenericError> for Error {
fn from(err: redis_module::error::GenericError) -> Error {
err.to_string().into()
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Error {
err.to_string().into()
}
}
impl From<ParseIntError> for Error {
fn from(err: ParseIntError) -> Error {
err.to_string().into()
}
}
impl From<redis_module::error::Error> for Error {
fn from(e: redis_module::error::Error) -> Self {
match e {
redis_module::error::Error::Generic(err) => err.into(),
redis_module::error::Error::FromUtf8(err) => err.into(),
redis_module::error::Error::ParseInt(err) => err.into(),
}
}
}
impl From<RedisError> for Error {
fn from(e: RedisError) -> Self {
Self::from(format!("ERR {}", e))
}
}
impl From<&str> for Error {
fn from(e: &str) -> Self {
Error { msg: e.to_string() }
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error { msg: e.to_string() }
}
}
impl From<JsonPathError> for Error {
fn from(e: JsonPathError) -> Self {
Error {
msg: format!("JSON Path error: {:?}", e).replace("\n", "\\n"),
}
}
}
impl From<Error> for redis_module::RedisError {
fn from(e: Error) -> Self {
redis_module::RedisError::String(e.msg)
}
}