diff options
-rw-r--r-- | src/mongo/util/assert_util.h | 16 | ||||
-rw-r--r-- | src/mongo/util/assert_util_test.cpp | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h index ae00f8e4053..29406946151 100644 --- a/src/mongo/util/assert_util.h +++ b/src/mongo/util/assert_util.h @@ -269,6 +269,14 @@ inline void fassertWithLocation(int msgid, bool testOK, const char* file, unsign } } +template <typename T> +inline T fassertWithLocation(int msgid, StatusWith<T> sw, const char* file, unsigned line) { + if (MONGO_unlikely(!sw.isOK())) { + fassertFailedWithStatusWithLocation(msgid, sw.getStatus(), file, line); + } + return std::move(sw.getValue()); +} + inline void fassertWithLocation(int msgid, const Status& status, const char* file, unsigned line) { if (MONGO_unlikely(!status.isOK())) { fassertFailedWithStatusWithLocation(msgid, status, file, line); @@ -284,6 +292,14 @@ inline void fassertNoTraceWithLocation(int msgid, bool testOK, const char* file, } } +template <typename T> +inline T fassertNoTraceWithLocation(int msgid, StatusWith<T> sw, const char* file, unsigned line) { + if (MONGO_unlikely(!sw.isOK())) { + fassertFailedWithStatusNoTraceWithLocation(msgid, sw.getStatus(), file, line); + } + return std::move(sw.getValue()); +} + inline void fassertNoTraceWithLocation(int msgid, const Status& status, const char* file, diff --git a/src/mongo/util/assert_util_test.cpp b/src/mongo/util/assert_util_test.cpp index e14fab9d643..a9d42dbb2a4 100644 --- a/src/mongo/util/assert_util_test.cpp +++ b/src/mongo/util/assert_util_test.cpp @@ -233,6 +233,12 @@ DEATH_TEST(FassertionTerminationTest, fassertOverload, "Terminating with fassert fassert(40207, {ErrorCodes::InternalError, "Terminating with fassert"}); } +DEATH_TEST(FassertionTerminationTest, fassertStatusWithOverload, "Terminating with fassert") { + fassert(50733, + StatusWith<std::string>{ErrorCodes::InternalError, + "Terminating with fassertStatusWithOverload"}); +} + DEATH_TEST(FassertionTerminationTest, fassertStatusOK, "Terminating with fassertStatusOK") { fassertStatusOK(40208, Status(ErrorCodes::InternalError, "Terminating with fassertStatusOK")); } @@ -243,6 +249,16 @@ DEATH_TEST(FassertionTerminationTest, fassertStatusOKOverload, "Terminating with StatusWith<std::string>(ErrorCodes::InternalError, "Terminating with fassertStatusOK")); } +DEATH_TEST(FassertionTerminationTest, fassertNoTrace, "Terminating with fassertNoTrace") { + fassertNoTrace(50734, Status(ErrorCodes::InternalError, "Terminating with fassertNoTrace")); +} + +DEATH_TEST(FassertionTerminationTest, fassertNoTraceOverload, "Terminating with fassertNoTrace") { + fassertNoTrace(50735, + StatusWith<std::string>(ErrorCodes::InternalError, + "Terminating with fassertNoTraceOverload")); +} + DEATH_TEST(FassertionTerminationTest, fassertFailed, "40210") { fassertFailed(40210); } |