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

chore(error): unify error by adding Redis error codes for Status #2362

Merged
merged 12 commits into from
Jun 15, 2024

Conversation

git-hulk
Copy link
Member

@git-hulk git-hulk commented Jun 11, 2024

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.

@git-hulk git-hulk force-pushed the unify-error-message branch 2 times, most recently from e647f02 to 694f099 Compare June 12, 2024 12:23
@git-hulk git-hulk changed the title chore(error): explicitly assign the type in Redis error chore(error): unify Redis error by explicitly using the error kind Jun 13, 2024
@git-hulk
Copy link
Member Author

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.

@git-hulk git-hulk marked this pull request as ready for review June 13, 2024 14:58
src/cluster/cluster.cc Outdated Show resolved Hide resolved
src/common/redis_error.h Outdated Show resolved Hide resolved
@PragmaTwice
Copy link
Member

PragmaTwice commented Jun 14, 2024

There are several points for the current changes:

  • We need to also add ErrorKind to StatusOr, otherwise it's not consistent between Status and StatusOr, which violates our design of StatusOr.
  • ErrorKind::None is weird and seems useless. Removing useless state is always a good thing to prevent unnecessary complex.
  • ErrorKind is not always useful in Status, since not all sink of Status goes to RESP error.

So I suggest maybe we can just merge ErrorKind to Status::Code, which seems a solution that can solve these issues.

@git-hulk
Copy link
Member Author

We need to also add ErrorKind to StatusOr, otherwise it's not consistent between Status and StatusOr, which violates our design of StatusOr.

Sure, would add this.

ErrorKind::None is weird and seems useless. Removing useless state is always a good thing to prevent unnecessary complex.

None is used to represent the error without the prefix.

ErrorKind is not always useful in Status, since not all sink of Status goes to RESP error.

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.

@git-hulk git-hulk changed the title chore(error): unify Redis error by explicitly using the error kind chore(error): unify error by adding Redis error codes for Status Jun 14, 2024
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:
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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.

@@ -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";
Copy link
Member

Choose a reason for hiding this comment

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

How about this one?

@PragmaTwice
Copy link
Member

return err == std::string(RESP_PREFIX_ERROR) + redis::errRestoringBackup;

Forget to change?

@git-hulk
Copy link
Member Author

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.

errRestoringBackup

Yes, good catch, fixed now.

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) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::string StatusToRedisError(const Status &s) {
std::string StatusToRedisErrorMsg(const Status &s) {

Maybe this name is better.

Copy link
Member

@PragmaTwice PragmaTwice Jun 15, 2024

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@git-hulk git-hulk merged commit 8f1d2ad into apache:unstable Jun 15, 2024
32 checks passed
Copy link

sonarcloud bot commented Jun 15, 2024

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.

None yet

4 participants