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

add ERR prefix to error #240

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ where
/// let hm: HMGetResult<'_, &str, RedisString> = ctx
/// .open_key(&key_name)
/// .hash_get_multi(fields)?
/// .ok_or(RedisError::Str("ERR key not found"))?;
/// .ok_or(RedisError::Str("key not found"))?;
/// let response: Vec<RedisValue> = hm.into_iter().map(|(_, v)| v.into()).collect();
/// Ok(RedisValue::Array(response))
/// }
Expand All @@ -482,7 +482,7 @@ where
/// let hm: HMGetResult<'_, &str, RedisString> = ctx
/// .open_key(&key_name)
/// .hash_get_multi(fields)?
/// .ok_or(RedisError::Str("ERR key not found"))?;
/// .ok_or(RedisError::Str("key not found"))?;
/// let response: Vec<RedisValue> = hm.into_iter().map(|(_, v)| RedisValue::BulkRedisString(v)).collect();
/// Ok(RedisValue::Array(response))
/// }
Expand Down
2 changes: 1 addition & 1 deletion src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ where

match res {
Status::Ok => Ok(()),
Status::Err => Err(RedisError::Str("ERR key is not a hash value")),
Status::Err => Err(RedisError::Str("key is not a hash value")),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/rediserror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ pub enum RedisError {
impl RedisError {
#[must_use]
pub const fn nonexistent_key() -> Self {
Self::Str("ERR could not perform this operation on a key that doesn't exist")
Self::Str("could not perform this operation on a key that doesn't exist")
}

#[must_use]
pub const fn short_read() -> Self {
Self::Str("ERR short read or OOM loading DB")
Self::Str("short read or OOM loading DB")
}
}

impl<T: std::error::Error> From<T> for RedisError {
fn from(e: T) -> Self {
Self::String(format!("ERR {e}"))
Self::String(e.to_string())
}
}

Expand All @@ -45,6 +45,6 @@ impl fmt::Display for RedisError {
Self::String(s) => s.as_str(),
};

write!(f, "{d}")
write!(f, "ERR {d}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaks test error::tests::test_to_redis_error

}
}