diff options
author | David Storch <david.storch@10gen.com> | 2016-05-23 17:55:01 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-05-25 14:40:31 -0400 |
commit | 439df4c3bdff0194cff402a6268a9bdb9de44a7a (patch) | |
tree | c1d0c8d613d65516cce48327d183776464016634 /src/mongo/db/index/s2_access_method.cpp | |
parent | 15deafbf2aa6524f3b05dd729b4ff378e18a2162 (diff) | |
download | mongo-439df4c3bdff0194cff402a6268a9bdb9de44a7a.tar.gz |
SERVER-23945 make IndexCatalog::_fixIndexSpec() use Status instead of throwing
Diffstat (limited to 'src/mongo/db/index/s2_access_method.cpp')
-rw-r--r-- | src/mongo/db/index/s2_access_method.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp index c6519519b44..a05f72855dc 100644 --- a/src/mongo/db/index/s2_access_method.cpp +++ b/src/mongo/db/index/s2_access_method.cpp @@ -80,7 +80,7 @@ S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState, SortedDataInterfac } // static -BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) { +StatusWith<BSONObj> S2AccessMethod::fixSpec(const BSONObj& specObj) { // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add // {2dsphereIndexVersion: 3}, which is the default for newly-built indexes. @@ -92,22 +92,33 @@ BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) { return bob.obj(); } - uassert(40108, - str::stream() << "Invalid type or value for geo index version { " - << kIndexVersionFieldName << " : " << indexVersionElt - << " }, only versions: [" << S2_INDEX_VERSION_1 << "," - << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported", - indexVersionElt.isNumber() && ((indexVersionElt.type() != mongo::NumberDouble) || - std::isnormal(indexVersionElt.numberDouble()))); + if (!indexVersionElt.isNumber()) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "Invalid type for geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } + + if (indexVersionElt.type() == BSONType::NumberDouble && + !std::isnormal(indexVersionElt.numberDouble())) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "Invalid value for geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } const auto indexVersion = indexVersionElt.numberLong(); + if (indexVersion != S2_INDEX_VERSION_1 && indexVersion != S2_INDEX_VERSION_2 && + indexVersion != S2_INDEX_VERSION_3) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "unsupported geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } - uassert(17394, - str::stream() << "unsupported geo index version { " << kIndexVersionFieldName << " : " - << indexVersionElt << " }, only versions: [" << S2_INDEX_VERSION_1 << "," - << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported", - (indexVersion == S2_INDEX_VERSION_3 || indexVersion == S2_INDEX_VERSION_2 || - indexVersion == S2_INDEX_VERSION_1)); return specObj; } |