diff options
Diffstat (limited to 'src/mongo/util/assert_util.cpp')
| -rw-r--r-- | src/mongo/util/assert_util.cpp | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index a85cda7e907..74f15881e7e 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "pch.h" +#include "mongo/pch.h" #include "mongo/util/assert_util.h" @@ -55,7 +55,8 @@ namespace mongo { bool DBException::traceExceptions = false; string DBException::toString() const { - stringstream ss; ss << getCode() << " " << what(); return ss.str(); + stringstream ss; + ss << getCode() << " " << what(); return ss.str(); } @@ -124,6 +125,14 @@ namespace mongo { throw e; } + NOINLINE_DECL void invariantFailed(const char *msg, const char *file, unsigned line) { + problem() << "Invariant failure " << msg << ' ' << file << ' ' << dec << line << endl; + logContext(); + breakpoint(); + log() << "\n\n***aborting after invariant() failure\n\n" << endl; + abort(); + } + NOINLINE_DECL void fassertFailed( int msgid ) { problem() << "Fatal Assertion " << msgid << endl; logContext(); @@ -132,6 +141,21 @@ namespace mongo { abort(); } + NOINLINE_DECL void fassertFailedNoTrace( int msgid ) { + problem() << "Fatal Assertion " << msgid << endl; + breakpoint(); + log() << "\n\n***aborting after fassert() failure\n\n" << endl; + ::_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()); } @@ -166,6 +190,34 @@ namespace mongo { throw MsgAssertionException(msgid, msg); } + void msgassertedNoTrace(int msgid, const std::string& msg) { + msgassertedNoTrace(msgid, msg.c_str()); + } + + std::string causedBy( const char* e ) { + return std::string(" :: caused by :: ") + e; + } + + std::string causedBy( const DBException& e ){ + return causedBy( e.toString() ); + } + + std::string causedBy( const std::exception& e ) { + return causedBy( e.what() ); + } + + std::string causedBy( const std::string& e ){ + return causedBy( e.c_str() ); + } + + std::string causedBy( const std::string* e ) { + return (e && *e != "") ? causedBy(*e) : ""; + } + + std::string causedBy( const Status& e ){ + return causedBy( e.reason() ); + } + NOINLINE_DECL void streamNotGood( int code , const std::string& msg , std::ios& myios ) { stringstream ss; // errno might not work on all systems for streams |
