Skip to content

Commit

Permalink
Change throw runtime_err to throw RedisError
Browse files Browse the repository at this point in the history
  • Loading branch information
liuh-80 committed Nov 27, 2023
1 parent 54c6839 commit da80db2
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion common/consumertable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void ConsumerTable::pops(deque<KeyOpFieldsValuesTuple> &vkco, const string &pref
if (i+1 >= ctx->elements)
{
SWSS_LOG_ERROR("invalid number of elements in returned table: %zu >= %zu", i+1, ctx->elements);
throw runtime_error("invalid number of elements in returned table");
throw RedisError("invalid number of elements in returned table");
}

FieldValueTuple e;
Expand Down
20 changes: 10 additions & 10 deletions common/dbconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ void SonicDBConfig::parseDatabaseConfig(const string &file,
catch (domain_error& e)
{
SWSS_LOG_ERROR("key doesn't exist in json object, NULL value has no iterator >> %s\n", e.what());
throw runtime_error("key doesn't exist in json object, NULL value has no iterator >> " + string(e.what()));
throw RedisError("key doesn't exist in json object, NULL value has no iterator >> " + string(e.what()));
}
catch (exception &e)
{
SWSS_LOG_ERROR("Sonic database config file syntax error >> %s\n", e.what());
throw runtime_error("Sonic database config file syntax error >> " + string(e.what()));
throw RedisError("Sonic database config file syntax error >> " + string(e.what()));
}
}
else
{
SWSS_LOG_ERROR("Sonic database config file doesn't exist at %s\n", file.c_str());
throw runtime_error("Sonic database config file doesn't exist at " + file);
throw RedisError("Sonic database config file doesn't exist at " + file);
}
}

Expand Down Expand Up @@ -143,12 +143,12 @@ void SonicDBConfig::initializeGlobalConfig(const string &file)
catch (domain_error& e)
{
SWSS_LOG_ERROR("key doesn't exist in json object, NULL value has no iterator >> %s\n", e.what());
throw runtime_error("key doesn't exist in json object, NULL value has no iterator >> " + string(e.what()));
throw RedisError("key doesn't exist in json object, NULL value has no iterator >> " + string(e.what()));
}
catch (exception &e)
{
SWSS_LOG_ERROR("Sonic database config file syntax error >> %s\n", e.what());
throw runtime_error("Sonic database config file syntax error >> " + string(e.what()));
throw RedisError("Sonic database config file syntax error >> " + string(e.what()));
}
}
else
Expand All @@ -173,7 +173,7 @@ void SonicDBConfig::initialize(const string &file)
if (m_init)
{
SWSS_LOG_ERROR("SonicDBConfig already initialized");
throw runtime_error("SonicDBConfig already initialized");
throw RedisError("SonicDBConfig already initialized");
}

parseDatabaseConfig(file, inst_entry, db_entry, separator_entry);
Expand Down Expand Up @@ -647,7 +647,7 @@ bool DBConnector::exists(const string &key)
if (key.find_first_of(" \t") != string::npos)
{
SWSS_LOG_ERROR("EXISTS failed, invalid space or tab in single key: %s", key.c_str());
throw runtime_error("EXISTS failed, invalid space or tab in single key");
throw RedisError("EXISTS failed, invalid space or tab in single key");
}
rexists.format("EXISTS %s", key.c_str());
RedisReply r(this, rexists, REDIS_REPLY_INTEGER);
Expand Down Expand Up @@ -785,7 +785,7 @@ shared_ptr<string> DBConnector::get(const string &key)
return ptr;
}

throw runtime_error("GET failed, memory exception");
throw RedisError("GET failed, memory exception");
}

shared_ptr<string> DBConnector::hget(const string &key, const string &field)
Expand All @@ -807,7 +807,7 @@ shared_ptr<string> DBConnector::hget(const string &key, const string &field)
}

SWSS_LOG_ERROR("HGET failed, reply-type: %d, %s: %s", reply->type, key.c_str(), field.c_str());
throw runtime_error("HGET failed, unexpected reply type, memory exception");
throw RedisError("HGET failed, unexpected reply type, memory exception");
}

bool DBConnector::hexists(const string &key, const string &field)
Expand Down Expand Up @@ -844,7 +844,7 @@ shared_ptr<string> DBConnector::blpop(const string &list, int timeout)
return ptr;
}

throw runtime_error("GET failed, memory exception");
throw RedisError("GET failed, memory exception");
}

void DBConnector::subscribe(const std::string &pattern)
Expand Down
5 changes: 3 additions & 2 deletions common/defaultvalueprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
#include <dirent.h>
#include <stdio.h>

#include "armhelper.h"
#include "defaultvalueprovider.h"
#include "logger.h"
#include "table.h"
#include "json.h"
#include "armhelper.h"
#include "redisreply.h"

using namespace std;
using namespace swss;

[[noreturn]] void ThrowRunTimeError(string message)
{
SWSS_LOG_ERROR("DefaultValueProvider: %s", message.c_str());
throw runtime_error(message);
throw RedisError(message);
}

TableInfoBase::TableInfoBase()
Expand Down
3 changes: 2 additions & 1 deletion common/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sys/wait.h>
#include "exec.h"
#include "common/logger.h"
#include "common/redisreply.h"

using namespace std;

Expand All @@ -21,7 +22,7 @@ int exec(const string &cmd, string &stdout)

errmsg = "popen(" + errmsg + ") failed!";
SWSS_LOG_ERROR("exec: %s", errmsg.c_str());
throw runtime_error(errmsg);
throw RedisError(errmsg);
}

stdout.clear();
Expand Down
3 changes: 2 additions & 1 deletion common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "dbconnector.h"
#include "subscriberstatetable.h"
#include "producerstatetable.h"
#include "redisreply.h"

using namespace swss;

Expand Down Expand Up @@ -324,7 +325,7 @@ void Logger::wthrow(Priority prio, const char *fmt, ...)
vsnprintf(buffer, 0x1000, fmt, ap);
va_end(ap);

throw std::runtime_error(buffer);
throw RedisError(buffer);
}

std::string Logger::priorityToString(Logger::Priority prio)
Expand Down
11 changes: 6 additions & 5 deletions common/notificationconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <deque>
#include "redisapi.h"
#include "redisreply.h"

#define NOTIFICATION_SUBSCRIBE_TIMEOUT (1000)
#define REDIS_PUBLISH_MESSAGE_INDEX (2)
Expand Down Expand Up @@ -75,7 +76,7 @@ uint64_t swss::NotificationConsumer::readData()
{
SWSS_LOG_ERROR("failed to read redis reply on channel %s", m_channel.c_str());

throw std::runtime_error("Unable to read redis reply");
throw RedisError("Unable to read redis reply");
}
else
{
Expand All @@ -98,7 +99,7 @@ uint64_t swss::NotificationConsumer::readData()

if (status != REDIS_OK)
{
throw std::runtime_error("Unable to read redis reply");
throw RedisError("Unable to read redis reply");
}
return 0;
}
Expand All @@ -121,7 +122,7 @@ void swss::NotificationConsumer::processReply(redisReply *reply)
{
SWSS_LOG_ERROR("expected ARRAY redis reply on channel %s, got: %d", m_channel.c_str(), reply->type);

throw std::runtime_error("getRedisReply operation failed");
throw RedisError("getRedisReply operation failed");
}

if (reply->elements != REDIS_PUBLISH_MESSAGE_ELEMNTS)
Expand All @@ -131,7 +132,7 @@ void swss::NotificationConsumer::processReply(redisReply *reply)
m_channel.c_str(),
reply->elements);

throw std::runtime_error("getRedisReply operation failed");
throw RedisError("getRedisReply operation failed");
}

std::string msg = std::string(reply->element[REDIS_PUBLISH_MESSAGE_INDEX]->str);
Expand All @@ -148,7 +149,7 @@ void swss::NotificationConsumer::pop(std::string &op, std::string &data, std::ve
if (m_queue.empty())
{
SWSS_LOG_ERROR("notification queue is empty, can't pop");
throw std::runtime_error("notification queue is empty, can't pop");
throw RedisError("notification queue is empty, can't pop");
}

std::string msg = m_queue.front();
Expand Down
2 changes: 1 addition & 1 deletion common/pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uint64_t PubSub::readData()
* read them second time. */
if (redisGetReply(m_subscribe->getContext(), reinterpret_cast<void**>(&reply)) != REDIS_OK)
{
throw std::runtime_error("Unable to read redis reply");
throw RedisError("Unable to read redis reply");
}

m_keyspace_event_buffer.emplace_back(make_shared<RedisReply>(reply));
Expand Down
4 changes: 2 additions & 2 deletions common/redisselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uint64_t RedisSelect::readData()
redisReply *reply = nullptr;

if (redisGetReply(m_subscribe->getContext(), reinterpret_cast<void**>(&reply)) != REDIS_OK)
throw std::runtime_error("Unable to read redis reply from RedisSelect::readData() redisGetReply()");
throw RedisError("Unable to read redis reply from RedisSelect::readData() redisGetReply()");

freeReplyObject(reply);
m_queueLength++;
Expand All @@ -47,7 +47,7 @@ uint64_t RedisSelect::readData()

if (status != REDIS_OK)
{
throw std::runtime_error("Unable to read redis reply from RedisSelect::readData() redisGetReplyFromReader()");
throw RedisError("Unable to read redis reply from RedisSelect::readData() redisGetReplyFromReader()");
}
return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions common/select.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common/selectable.h"
#include "common/logger.h"
#include "common/redisreply.h"
#include "common/select.h"
#include <algorithm>
#include <stdio.h>
Expand All @@ -22,7 +23,7 @@ Select::Select()
std::string error = std::string("Select::constructor:epoll_create1: error=("
+ std::to_string(errno) + "}:"
+ strerror(errno));
throw std::runtime_error(error);
throw RedisError(error);
}
}

Expand Down Expand Up @@ -59,7 +60,7 @@ void Select::addSelectable(Selectable *selectable)
std::string error = std::string("Select::add_fd:epoll_ctl: error=("
+ std::to_string(errno) + "}:"
+ strerror(errno));
throw std::runtime_error(error);
throw RedisError(error);
}
}

Expand All @@ -76,7 +77,7 @@ void Select::removeSelectable(Selectable *selectable)
std::string error = std::string("Select::del_fd:epoll_ctl: error=("
+ std::to_string(errno) + "}:"
+ strerror(errno));
throw std::runtime_error(error);
throw RedisError(error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/selectableevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SelectableEvent::SelectableEvent(int pri) :
{
SWSS_LOG_ERROR("failed to create eventfd, errno: %s", strerror(errno));

throw std::runtime_error("failed to create eventfd");
throw RedisError("failed to create eventfd");
}
}

Expand Down Expand Up @@ -75,7 +75,7 @@ void SelectableEvent::notify()
{
SWSS_LOG_ERROR("write failed, errno: %s", strerror(errno));

throw std::runtime_error("write failed");
throw RedisError("write failed");
}
}

Expand Down
5 changes: 3 additions & 2 deletions common/subscriberstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "selectable.h"
#include "redisselect.h"
#include "redisapi.h"
#include "redisreply.h"
#include "tokenize.h"
#include "subscriberstatetable.h"

Expand Down Expand Up @@ -52,7 +53,7 @@ uint64_t SubscriberStateTable::readData()
* read them second time. */
if (redisGetReply(m_subscribe->getContext(), reinterpret_cast<void**>(&reply)) != REDIS_OK)
{
throw std::runtime_error("Unable to read redis reply");
throw RedisError("Unable to read redis reply");
}

m_keyspace_event_buffer.emplace_back(make_shared<RedisReply>(reply));
Expand All @@ -77,7 +78,7 @@ uint64_t SubscriberStateTable::readData()

if (status != REDIS_OK)
{
throw std::runtime_error("Unable to read redis reply");
throw RedisError("Unable to read redis reply");
}
return 0;
}
Expand Down

0 comments on commit da80db2

Please sign in to comment.