From 6d2f0d50009f4885d941674fa457a5faf6139032 Mon Sep 17 00:00:00 2001 From: sewenew Date: Thu, 15 Jun 2023 23:26:17 +0800 Subject: [PATCH] remove unreachable code branches --- src/sw/redis++/async_connection.cpp | 1 - src/sw/redis++/async_connection.h | 2 -- src/sw/redis++/async_subscriber_impl.cpp | 9 +++++---- src/sw/redis++/command.cpp | 1 - src/sw/redis++/connection.cpp | 1 - src/sw/redis++/errors.cpp | 9 --------- src/sw/redis++/reply.h | 2 +- src/sw/redis++/subscriber.cpp | 9 +++++---- src/sw/redis++/subscriber.h | 3 ++- test/src/sw/redis++/test_main.cpp | 1 - 10 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/sw/redis++/async_connection.cpp b/src/sw/redis++/async_connection.cpp index db6f351a..943b3bea 100644 --- a/src/sw/redis++/async_connection.cpp +++ b/src/sw/redis++/async_connection.cpp @@ -132,7 +132,6 @@ AsyncConnection::AsyncConnection(const ConnectionOptions &opts, default: throw Error("not supporeted async connection mode"); - break; } } diff --git a/src/sw/redis++/async_connection.h b/src/sw/redis++/async_connection.h index e62a40ad..2915a66e 100644 --- a/src/sw/redis++/async_connection.h +++ b/src/sw/redis++/async_connection.h @@ -544,11 +544,9 @@ class ClusterEvent : public CommandEvent { switch (event->_state) { case State::MOVED: throw Error("too many moved error"); - break; case State::ASKING: throw Error("Slot migrating..."); - break; default: break; diff --git a/src/sw/redis++/async_subscriber_impl.cpp b/src/sw/redis++/async_subscriber_impl.cpp index 0bf81860..1162135f 100644 --- a/src/sw/redis++/async_subscriber_impl.cpp +++ b/src/sw/redis++/async_subscriber_impl.cpp @@ -74,7 +74,9 @@ void AsyncSubscriberImpl::_run_callback(redisReply &reply) { break; default: - assert(false); + assert(type == Subscriber::MsgType::UNKNOWN); + + throw ProtoError("unknown message type."); } } @@ -99,10 +101,9 @@ Subscriber::MsgType AsyncSubscriberImpl::_msg_type(const std::string &type) cons return Subscriber::MsgType::PSUBSCRIBE; } else if ("punsubscribe" == type) { return Subscriber::MsgType::PUNSUBSCRIBE; + } else { + return Subscriber::MsgType::UNKNOWN; } - - throw ProtoError("Invalid message type."); - return Subscriber::MsgType::MESSAGE; // Silence "no return" warnings. } void AsyncSubscriberImpl::_handle_message(redisReply &reply) { diff --git a/src/sw/redis++/command.cpp b/src/sw/redis++/command.cpp index 97d9d44a..68baa15d 100644 --- a/src/sw/redis++/command.cpp +++ b/src/sw/redis++/command.cpp @@ -347,7 +347,6 @@ void set_geo_unit(CmdArgs &args, GeoUnit unit) { default: throw Error("Unknown geo unit type"); - break; } } diff --git a/src/sw/redis++/connection.cpp b/src/sw/redis++/connection.cpp index 04ba8609..7b060e01 100644 --- a/src/sw/redis++/connection.cpp +++ b/src/sw/redis++/connection.cpp @@ -169,7 +169,6 @@ std::string ConnectionOptions::_server_info() const { default: // Never goes here. throw Error("unknown connection type"); - break; } return info; diff --git a/src/sw/redis++/errors.cpp b/src/sw/redis++/errors.cpp index def15396..685933b5 100644 --- a/src/sw/redis++/errors.cpp +++ b/src/sw/redis++/errors.cpp @@ -54,28 +54,22 @@ void throw_error(const redisContext &context, const std::string &err_info) { } else { throw IoError(err_msg); } - break; case REDIS_ERR_EOF: throw ClosedError(err_msg); - break; case REDIS_ERR_PROTOCOL: throw ProtoError(err_msg); - break; case REDIS_ERR_OOM: throw OomError(err_msg); - break; case REDIS_ERR_OTHER: throw Error(err_msg); - break; #ifdef REDIS_ERR_TIMEOUT case REDIS_ERR_TIMEOUT: throw TimeoutError(err_msg); - break; #endif default: @@ -99,15 +93,12 @@ void throw_error(const redisReply &reply) { switch (err_type) { case ReplyErrorType::MOVED: throw MovedError(err_msg); - break; case ReplyErrorType::ASK: throw AskError(err_msg); - break; default: throw ReplyError(err_str); - break; } } diff --git a/src/sw/redis++/reply.h b/src/sw/redis++/reply.h index 605c33db..e78fe164 100644 --- a/src/sw/redis++/reply.h +++ b/src/sw/redis++/reply.h @@ -426,8 +426,8 @@ T parse(ParseTag, redisReply &reply) { throw ParseError("ARRAY or SET", reply); #else if (!is_array(reply)) { -#endif throw ParseError("ARRAY", reply); +#endif } T container; diff --git a/src/sw/redis++/subscriber.cpp b/src/sw/redis++/subscriber.cpp index f039b987..06575ec9 100644 --- a/src/sw/redis++/subscriber.cpp +++ b/src/sw/redis++/subscriber.cpp @@ -109,7 +109,9 @@ void Subscriber::consume() { break; default: - assert(false); + assert(type == MsgType::UNKNOWN); + + throw ProtoError("unknown message type."); } } @@ -135,10 +137,9 @@ Subscriber::MsgType Subscriber::_msg_type(std::string const& type) const return MsgType::PSUBSCRIBE; } else if ("punsubscribe" == type) { return MsgType::PUNSUBSCRIBE; + } else { + return MsgType::UNKNOWN; } - - throw ProtoError("Invalid message type."); - return MsgType::MESSAGE; // Silence "no return" warnings. } void Subscriber::_check_connection() { diff --git a/src/sw/redis++/subscriber.h b/src/sw/redis++/subscriber.h index 7e642474..654f4b4c 100644 --- a/src/sw/redis++/subscriber.h +++ b/src/sw/redis++/subscriber.h @@ -76,7 +76,8 @@ class Subscriber { PSUBSCRIBE, PUNSUBSCRIBE, MESSAGE, - PMESSAGE + PMESSAGE, + UNKNOWN }; template diff --git a/test/src/sw/redis++/test_main.cpp b/test/src/sw/redis++/test_main.cpp index 55c3c622..5998e90d 100644 --- a/test/src/sw/redis++/test_main.cpp +++ b/test/src/sw/redis++/test_main.cpp @@ -321,7 +321,6 @@ auto parse_options(int argc, char **argv) default: throw sw::redis::Error("Unknown command line option"); - break; } } catch (const sw::redis::Error &e) { print_help();