-
Notifications
You must be signed in to change notification settings - Fork 437
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
chore(error): unify error by adding Redis error codes for Status #2362
Conversation
e647f02
to
694f099
Compare
By the way, I found some error messages aren't aligned with Redis, but I don't prefer fixing them in this PR. Will submit another PR to resolve this, as well as to reduce some of the redundant status codes. |
There are several points for the current changes:
So I suggest maybe we can just merge ErrorKind to Status::Code, which seems a solution that can solve these issues. |
Sure, would add this.
None is used to represent the error without the prefix.
Yes, not all status errors can be mapped to the RESP error, and I think it's still important to identify the status error via code. That's why I used the RedisError to identify them. |
e618aee
to
045b087
Compare
std::to_string(SORT_LENGTH_LIMIT)); | ||
break; | ||
return {Status::RedisErrorNoPrefix, | ||
"The number of elements to be sorted exceeds SORT_LENGTH_LIMIT = " + std::to_string(SORT_LENGTH_LIMIT)}; | ||
case Database::SortResult::DONE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's really no prefix? Or just because we forget to add the prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this. I found we have some places that didn't align with Redis, but I suggest revising and fixing them in another PR: #2362 (comment)
@@ -230,7 +230,7 @@ class CommandFetchMeta : public Commander { | |||
std::string files; | |||
auto s = engine::Storage::ReplDataManager::GetFullReplDataInfo(srv->storage, &files); | |||
if (!s.IsOK()) { | |||
s = util::SockSend(repl_fd, redis::Error("can't create db checkpoint"), bev); | |||
s = util::SockSend(repl_fd, redis::Error({Status::RedisErrorNoPrefix, "can't create db checkpoint"}), bev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If here it's because we forget to add the prefix, we should fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the above comment.
src/commands/error_constants.h
Outdated
@@ -40,10 +40,10 @@ inline constexpr const char *errLimitOptionNotAllowed = | |||
inline constexpr const char *errZSetLTGTNX = "GT, LT, and/or NX options at the same time are not compatible"; | |||
inline constexpr const char *errScoreIsNotValidFloat = "score is not a valid float"; | |||
inline constexpr const char *errValueIsNotFloat = "value is not a valid float"; | |||
inline constexpr const char *errNoMatchingScript = "NOSCRIPT No matching script. Please use EVAL"; | |||
inline constexpr const char *errNoMatchingScript = "No matching script. Please use EVAL"; | |||
inline constexpr const char *errUnknownOption = "unknown option"; | |||
inline constexpr const char *errUnknownSubcommandOrWrongArguments = "Unknown subcommand or wrong number of arguments"; | |||
inline constexpr const char *errWrongNumArguments = "ERR wrong number of arguments"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this one?
kvrocks/src/cluster/replication.cc Line 1003 in 84a3559
Forget to change? |
Yes, good catch, fixed now. |
src/server/redis_reply.cc
Outdated
std::string Error(const std::string &err) { return "-" + err + CRLF; } | ||
std::string Error(const Status &s) { return RESP_PREFIX_ERROR + StatusToRedisError(s); } | ||
|
||
std::string StatusToRedisError(const Status &s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string StatusToRedisError(const Status &s) { | |
std::string StatusToRedisErrorMsg(const Status &s) { |
Maybe this name is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can distinguish between redis error message and resp errors.
- redis error message ->
<PREFIX> <message..>
- resp error ->
- <redis error message> CRLF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
This PR introduces new error codes to identify Redis error prefixes,
and forces using status to unify Redis errors. You MUST convert
it to Status to send a Redis error response.