Skip to content

Commit

Permalink
Fix wrong error message
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Jun 15, 2024
1 parent 3684950 commit 60cd76b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/cluster/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,18 @@ Status ReplicationThread::parseWriteBatch(const std::string &batch_string) {
}

bool ReplicationThread::isRestoringError(std::string_view err) {
return err == redis::Error({Status::RedisLoading, redis::errRestoringBackup});
// err doesn't contain the CRLF, so cannot use redis::Error here.
return err == RESP_PREFIX_ERROR + redis::StatusToRedisError({Status::RedisLoading, redis::errRestoringBackup});
}

bool ReplicationThread::isWrongPsyncNum(std::string_view err) {
return err == redis::Error({Status::NotOK, redis::errWrongNumArguments});
// err doesn't contain the CRLF, so cannot use redis::Error here.
return err == RESP_PREFIX_ERROR + redis::StatusToRedisError({Status::NotOK, redis::errWrongNumArguments});
}

bool ReplicationThread::isUnknownOption(std::string_view err) {
return err == redis::Error({Status::NotOK, redis::errUnknownOption});
// err doesn't contain the CRLF, so cannot use redis::Error here.
return err == RESP_PREFIX_ERROR + redis::StatusToRedisError({Status::NotOK, redis::errUnknownOption});
}

rocksdb::Status WriteBatchHandler::PutCF(uint32_t column_family_id, const rocksdb::Slice &key,
Expand Down
8 changes: 4 additions & 4 deletions src/server/redis_reply.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ void Reply(evbuffer *output, const std::string &data) { evbuffer_add(output, dat

std::string SimpleString(const std::string &data) { return "+" + data + CRLF; }

std::string Error(const Status &s) { return RESP_PREFIX_ERROR + StatusToRedisError(s); }
std::string Error(const Status &s) { return RESP_PREFIX_ERROR + StatusToRedisError(s) + CRLF; }

std::string StatusToRedisError(const Status &s) {
CHECK(!s.IsOK());
std::string prefix = "ERR";
if (auto it = redisErrorPrefixMapping.find(s.GetCode()); it != redisErrorPrefixMapping.end()) {
prefix = it->second;
}
if (!prefix.empty()) {
prefix = prefix + " ";
if (prefix.empty()) {
return s.Msg();
}
return prefix + s.Msg() + CRLF;
return prefix + " " + s.Msg();
}

std::string BulkString(const std::string &data) { return "$" + std::to_string(data.length()) + CRLF + data + CRLF; }
Expand Down

0 comments on commit 60cd76b

Please sign in to comment.