summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/util/net/cidr.cpp16
-rw-r--r--src/mongo/util/net/cidr.h5
-rw-r--r--src/mongo/util/net/cidr_test.cpp7
3 files changed, 9 insertions, 19 deletions
diff --git a/src/mongo/util/net/cidr.cpp b/src/mongo/util/net/cidr.cpp
index d8fe660eb23..11de75bb7de 100644
--- a/src/mongo/util/net/cidr.cpp
+++ b/src/mongo/util/net/cidr.cpp
@@ -96,8 +96,8 @@ StatusWith<CIDR> CIDR::parse(BSONElement from) noexcept {
StatusWith<CIDR> CIDR::parse(StringData s) noexcept try {
return CIDR(s);
-} catch (const CIDRException& e) {
- return {ErrorCodes::UnsupportedFormat, e.what()};
+} catch (const DBException& e) {
+ return e.toStatus();
}
CIDR::CIDR(StringData s) try {
@@ -111,7 +111,7 @@ CIDR::CIDR(StringData s) try {
_family = AF_INET6;
_len = kIPv6Bits;
} else {
- throw CIDRException("Invalid IP address in CIDR string");
+ uasserted(ErrorCodes::UnsupportedFormat, "Invalid IP address in CIDR string");
}
if (slash == end(s)) {
@@ -119,15 +119,15 @@ CIDR::CIDR(StringData s) try {
}
auto len = strict_stoi(std::string(slash + 1, end(s)), 10);
- if ((len < 0) || (len > _len)) {
- throw CIDRException("Invalid length in CIDR string");
- }
+ uassert(ErrorCodes::UnsupportedFormat,
+ "Invalid length in CIDR string",
+ (len >= 0) && (len <= _len));
_len = len;
} catch (const std::invalid_argument& e) {
- throw CIDRException("Non-numeric length in CIDR string");
+ uasserted(ErrorCodes::UnsupportedFormat, "Non-numeric length in CIDR string");
} catch (const std::out_of_range& e) {
- throw CIDRException("Invalid length in CIDR string");
+ uasserted(ErrorCodes::UnsupportedFormat, "Invalid length in CIDR string");
}
template <>
diff --git a/src/mongo/util/net/cidr.h b/src/mongo/util/net/cidr.h
index bd10d32dbc1..62c873971b9 100644
--- a/src/mongo/util/net/cidr.h
+++ b/src/mongo/util/net/cidr.h
@@ -42,11 +42,6 @@
namespace mongo {
-class CIDRException : public DBException {
-public:
- CIDRException(const StringData& w) : DBException(ErrorCodes::BadValue, w.toString()) {}
-};
-
/**
* CIDR (Classless Inter-Domain Routing)
*/
diff --git a/src/mongo/util/net/cidr_test.cpp b/src/mongo/util/net/cidr_test.cpp
index 3001cf18e31..d15ce89af59 100644
--- a/src/mongo/util/net/cidr_test.cpp
+++ b/src/mongo/util/net/cidr_test.cpp
@@ -237,12 +237,7 @@ TEST(CIDRTest, doesNotParse) {
{"candygram", kBadIp},
};
for (auto&& p : bad_addrs) {
- try {
- CIDR cidr(p.first);
- ASSERT_TRUE(false);
- } catch (const CIDRException& e) {
- ASSERT_EQUALS(e.what(), p.second);
- }
+ ASSERT_THROWS_WHAT(CIDR(p.first), DBException, p.second);
}
}