diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-10-16 18:59:08 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-11-02 14:25:21 -0400 |
commit | a0ebc55db521792632fb3ece87edafec327cc2a9 (patch) | |
tree | b2098c89f241082a9c1a55ed69794eef210aa312 /src/mongo/client/mongo_uri.cpp | |
parent | 9f8696b5ba4c9310749c5c3f1ee082c5f663b5b0 (diff) | |
download | mongo-a0ebc55db521792632fb3ece87edafec327cc2a9.tar.gz |
SERVER-31622 Fix bad throws
Diffstat (limited to 'src/mongo/client/mongo_uri.cpp')
-rw-r--r-- | src/mongo/client/mongo_uri.cpp | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp index e7c500d719b..ba2bbbc1384 100644 --- a/src/mongo/client/mongo_uri.cpp +++ b/src/mongo/client/mongo_uri.cpp @@ -131,10 +131,10 @@ MongoURI::OptionsMap parseOptions(StringData options, StringData url) { } if (options.find('?') != std::string::npos) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() - << "URI Cannot Contain multiple questions marks for mongodb:// URL: " - << url); + uasserted( + ErrorCodes::FailedToParse, + str::stream() << "URI Cannot Contain multiple questions marks for mongodb:// URL: " + << url); } const auto optionsStr = options.toString(); @@ -144,24 +144,23 @@ MongoURI::OptionsMap parseOptions(StringData options, StringData url) { ++i) { const auto opt = boost::copy_range<std::string>(*i); if (opt.empty()) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() - << "Missing a key/value pair in the options for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() + << "Missing a key/value pair in the options for mongodb:// URL: " + << url); } const auto kvPair = partitionForward(opt, '='); const auto keyRaw = kvPair.first; if (keyRaw.empty()) { - throw DBException( - ErrorCodes::FailedToParse, - str::stream() - << "Missing a key for key/value pair in the options for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() + << "Missing a key for key/value pair in the options for mongodb:// URL: " + << url); } const auto key = uriDecode(keyRaw); if (!key.isOK()) { - throw DBException( + uasserted( ErrorCodes::FailedToParse, str::stream() << "Key '" << keyRaw << "' in options cannot properly be URL decoded for mongodb:// URL: " @@ -169,14 +168,14 @@ MongoURI::OptionsMap parseOptions(StringData options, StringData url) { } const auto valRaw = kvPair.second; if (valRaw.empty()) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() << "Missing value for key '" << keyRaw - << "' in the options for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Missing value for key '" << keyRaw + << "' in the options for mongodb:// URL: " + << url); } const auto val = uriDecode(valRaw); if (!val.isOK()) { - throw DBException( + uasserted( ErrorCodes::FailedToParse, str::stream() << "Value '" << valRaw << "' for key '" << keyRaw << "' in options cannot properly be URL decoded for mongodb:// URL: " @@ -232,7 +231,7 @@ MongoURI MongoURI::parseImpl(const std::string& url) { // 2.b Make sure that there are no question marks in the left side of the / // as any options after the ? must still have the / delimeter if (databaseAndOptions.empty() && userAndHostInfo.find('?') != std::string::npos) { - throw DBException( + uasserted( ErrorCodes::FailedToParse, str::stream() << "URI must contain slash delimeter between hosts and options for mongodb:// URL: " @@ -259,32 +258,30 @@ MongoURI MongoURI::parseImpl(const std::string& url) { }; if (containsColonOrAt(usernameSD)) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() << "Username must be URL Encoded for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Username must be URL Encoded for mongodb:// URL: " << url); } if (containsColonOrAt(passwordSD)) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() << "Password must be URL Encoded for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Password must be URL Encoded for mongodb:// URL: " << url); } // Get the username and make sure it did not fail to decode const auto usernameWithStatus = uriDecode(usernameSD); if (!usernameWithStatus.isOK()) { - throw DBException( - ErrorCodes::FailedToParse, - str::stream() << "Username cannot properly be URL decoded for mongodb:// URL: " << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Username cannot properly be URL decoded for mongodb:// URL: " + << url); } const auto username = usernameWithStatus.getValue(); // Get the password and make sure it did not fail to decode const auto passwordWithStatus = uriDecode(passwordSD); if (!passwordWithStatus.isOK()) - throw DBException( - ErrorCodes::FailedToParse, - str::stream() << "Password cannot properly be URL decoded for mongodb:// URL: " << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Password cannot properly be URL decoded for mongodb:// URL: " + << url); const auto password = passwordWithStatus.getValue(); // 5. Validate, split, and URL decode the host identifiers. @@ -296,9 +293,9 @@ MongoURI MongoURI::parseImpl(const std::string& url) { ++i) { const auto hostWithStatus = uriDecode(boost::copy_range<std::string>(*i)); if (!hostWithStatus.isOK()) { - throw DBException( - ErrorCodes::FailedToParse, - str::stream() << "Host cannot properly be URL decoded for mongodb:// URL: " << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Host cannot properly be URL decoded for mongodb:// URL: " + << url); } const auto host = hostWithStatus.getValue(); @@ -307,7 +304,7 @@ MongoURI MongoURI::parseImpl(const std::string& url) { } if ((host.find('/') != std::string::npos) && !StringData(host).endsWith(".sock")) { - throw DBException( + uasserted( ErrorCodes::FailedToParse, str::stream() << "'" << host << "' in '" << url << "' appears to be a unix socket, but does not end in '.sock'"); @@ -316,7 +313,7 @@ MongoURI MongoURI::parseImpl(const std::string& url) { servers.push_back(uassertStatusOK(HostAndPort::parse(host))); } if (servers.empty()) { - throw DBException(ErrorCodes::FailedToParse, "No server(s) specified"); + uasserted(ErrorCodes::FailedToParse, "No server(s) specified"); } const std::string canonicalHost = servers.front().host(); @@ -324,8 +321,8 @@ MongoURI MongoURI::parseImpl(const std::string& url) { // domain name. Take that list of servers as the new list of servers. if (isSeedlist) { if (servers.size() > 1) { - throw DBException(ErrorCodes::FailedToParse, - "Only a single server may be specified with a mongo+srv:// url."); + uasserted(ErrorCodes::FailedToParse, + "Only a single server may be specified with a mongo+srv:// url."); } auto srvEntries = dns::lookupSRVRecords("_mongodb._tcp." + canonicalHost); servers.clear(); @@ -343,10 +340,10 @@ MongoURI MongoURI::parseImpl(const std::string& url) { const auto connectionOptions = dbAndOpts.second; const auto databaseWithStatus = uriDecode(databaseSD); if (!databaseWithStatus.isOK()) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() << "Database name cannot properly be URL " - "decoded for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Database name cannot properly be URL " + "decoded for mongodb:// URL: " + << url); } const auto database = databaseWithStatus.getValue(); @@ -357,10 +354,10 @@ MongoURI MongoURI::parseImpl(const std::string& url) { if (!database.empty() && !NamespaceString::validDBName(database, NamespaceString::DollarInDbNameBehavior::Disallow)) { - throw DBException(ErrorCodes::FailedToParse, - str::stream() << "Database name cannot have reserved " - "characters for mongodb:// URL: " - << url); + uasserted(ErrorCodes::FailedToParse, + str::stream() << "Database name cannot have reserved " + "characters for mongodb:// URL: " + << url); } // 8. Validate, split, and URL decode the connection options |