summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErin McNulty <erin.mcnulty@mongodb.com>2022-06-21 21:21:07 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-21 22:28:09 +0000
commit43efa77bd3107e1f72f7efbb0ef11fc2b07e2c13 (patch)
treeaafddfcc16530ef1133652c17da6b1ed4ba1ce0b
parentd9dae5b61f238da82fd2caf5952e87d491ec05f1 (diff)
downloadmongo-43efa77bd3107e1f72f7efbb0ef11fc2b07e2c13.tar.gz
SERVER-66345: Add a MONGO_UNIMPLEMENTED
-rw-r--r--src/mongo/util/assert_util.h18
-rw-r--r--src/mongo/util/assert_util_test.cpp14
2 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h
index e3ca9855b4c..75be98e5734 100644
--- a/src/mongo/util/assert_util.h
+++ b/src/mongo/util/assert_util.h
@@ -709,3 +709,21 @@ Status exceptionToStatus() noexcept;
* Like `MONGO_UNREACHABLE`, but triggers a `tassert` instead of an `invariant`
*/
#define MONGO_UNREACHABLE_TASSERT(msgid) tasserted(msgid, "Hit a MONGO_UNREACHABLE_TASSERT!")
+
+/**
+ * Produces an invariant failure if executed. Subset of MONGO_UNREACHABLE, but specifically
+ * to indicate that the program has reached a function that is unimplemented and should be
+ * unreachable from production.
+ * Example:
+ *
+ * void myFuncToDo() {
+ * MONGO_UNIMPLEMENTED;
+ * }
+ */
+#define MONGO_UNIMPLEMENTED \
+ ::mongo::invariantFailed("Hit a MONGO_UNIMPLEMENTED!", __FILE__, __LINE__);
+
+/**
+ * Like `MONGO_UNIMPLEMENTED`, but triggers a `tassert` instead of an `invariant`
+ */
+#define MONGO_UNIMPLEMENTED_TASSERT(msgid) tasserted(msgid, "Hit a MONGO_UNIMPLEMENTED_TASSERT!")
diff --git a/src/mongo/util/assert_util_test.cpp b/src/mongo/util/assert_util_test.cpp
index 8d2688eaacc..ff2f0243aef 100644
--- a/src/mongo/util/assert_util_test.cpp
+++ b/src/mongo/util/assert_util_test.cpp
@@ -336,6 +336,16 @@ DEATH_TEST(TassertTerminationTest, mongoUnreachableNonFatal, "Hit a MONGO_UNREAC
}
}
+DEATH_TEST_REGEX(TassertTerminationTest,
+ mongoUnimplementedNonFatal,
+ "6634500.*Hit a MONGO_UNIMPLEMENTED_TASSERT!") {
+ try {
+ MONGO_UNIMPLEMENTED_TASSERT(6634500);
+ } catch (const DBException&) {
+ // Catch the DBException, to ensure that we eventually abort during clean exit.
+ }
+}
+
// fassert and its friends
DEATH_TEST(FassertionTerminationTest, fassert, "40206") {
fassert(40206, false);
@@ -392,6 +402,10 @@ DEATH_TEST(InvariantTerminationTest, invariantOverload, "Terminating with invari
invariant(Status(ErrorCodes::InternalError, "Terminating with invariant"));
}
+DEATH_TEST(InvariantTerminationTest, mongoUnimplementedFatal, "Hit a MONGO_UNIMPLEMENTED!") {
+ MONGO_UNIMPLEMENTED;
+}
+
DEATH_TEST(InvariantTerminationTest, invariantStatusWithOverload, "Terminating with invariant") {
invariant(StatusWith<std::string>(ErrorCodes::InternalError,
"Terminating with invariantStatusWithOverload"));