diff options
author | Andy Schwerin <schwerin@10gen.com> | 2013-10-05 12:12:20 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2013-10-05 14:01:04 -0400 |
commit | c09abfd19ee0787f505e17d1c50c24ec049e88f5 (patch) | |
tree | 3179c6e94ade7c7f4ef4ea8f6e330a7c35e2b1a6 /src/mongo/util | |
parent | 2ecb17f186ba8bde7dd22c409b1c93be6ba08a79 (diff) | |
download | mongo-c09abfd19ee0787f505e17d1c50c24ec049e88f5.tar.gz |
Add new form of fassert that takes a Status instead of a bool.
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/assert_util.cpp | 8 | ||||
-rw-r--r-- | src/mongo/util/assert_util.h | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index 45fa0f2c8ad..8e220c019e9 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -140,6 +140,14 @@ namespace mongo { ::_exit(EXIT_ABRUPT); // bypass our handler for SIGABRT, which prints a stack trace. } + MONGO_COMPILER_NORETURN void fassertFailedWithStatus(int msgid, const Status& status) { + problem() << "Fatal assertion " << msgid << " " << status; + logContext(); + breakpoint(); + log() << "\n\n***aborting after fassert() failure\n\n" << endl; + abort(); + } + void uasserted(int msgid , const string &msg) { uasserted(msgid, msg.c_str()); } diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h index 8ea5f356846..5aa6c3f7291 100644 --- a/src/mongo/util/assert_util.h +++ b/src/mongo/util/assert_util.h @@ -168,6 +168,7 @@ namespace mongo { void wasserted(const char *msg, const char *file, unsigned line); MONGO_COMPILER_NORETURN void fassertFailed( int msgid ); MONGO_COMPILER_NORETURN void fassertFailedNoTrace( int msgid ); + MONGO_COMPILER_NORETURN void fassertFailedWithStatus(int msgid, const Status& status); /** a "user assertion". throws UserAssertion. logs. typically used for errors that a user could cause, such as duplicate key, disk full, etc. @@ -197,6 +198,11 @@ namespace mongo { /** aborts on condition failure */ inline void fassert(int msgid, bool testOK) {if (MONGO_unlikely(!testOK)) fassertFailed(msgid);} + inline void fassert(int msgid, const Status& status) { + if (MONGO_unlikely(!status.isOK())) { + fassertFailedWithStatus(msgid, status); + } + } /* "user assert". if asserts, user did something wrong, not our code */ |