Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use code in getLastError SERVER-112

  • Loading branch information...
commit d5a5401f9ae5aacaf41cb34e70c8e9eecf1b2fb9 1 parent fa8961c
@erh erh authored
View
3  buildscripts/errorcodes.py
@@ -80,6 +80,5 @@ def checkDups( fileName , lineNum , line , code ):
if __name__ == "__main__":
ok = checkErrorCodes()
print( "ok:" + str( ok ) )
- if ok == False:
- print( "next: " + str( getNextCode() ) )
+ print( "next: " + str( getNextCode() ) )
View
2  db/lasterror.cpp
@@ -40,6 +40,8 @@ namespace mongo {
b.appendNull( "err" );
else
b.append( "err", msg );
+ if ( code )
+ b.append( "code" , code );
if ( updatedExisting != NotUpdate )
b.appendBool( "updatedExisting", updatedExisting == True );
b.append( "n", nObjects );
View
9 db/lasterror.h
@@ -26,6 +26,7 @@ namespace mongo {
class Message;
struct LastError {
+ int code;
string msg;
enum UpdatedExistingType { NotUpdate, True, False } updatedExisting;
/* todo: nObjects should be 64 bit */
@@ -33,8 +34,9 @@ namespace mongo {
int nPrev;
bool valid;
bool overridenById;
- void raiseError(const char *_msg) {
+ void raiseError(int _code , const char *_msg) {
reset( true );
+ code = _code;
msg = _msg;
}
void recordUpdate( bool _updatedExisting, int nChanged ) {
@@ -51,6 +53,7 @@ namespace mongo {
reset();
}
void reset( bool _valid = false ) {
+ code = 0;
msg.clear();
updatedExisting = NotUpdate;
nObjects = 0;
@@ -93,13 +96,13 @@ namespace mongo {
map<int,Status> _ids;
} lastError;
- inline void raiseError(const char *msg) {
+ inline void raiseError(int code , const char *msg) {
LastError *le = lastError.get();
if ( le == 0 ) {
DEV log() << "warning: lastError==0 can't report:" << msg << '\n';
return;
}
- le->raiseError(msg);
+ le->raiseError(code, msg);
}
inline void recordUpdate( bool updatedExisting, int nChanged ) {
View
2  db/pdfile.cpp
@@ -1532,7 +1532,7 @@ namespace mongo {
if( !ok ) {
log() << "failed to drop index after a unique key error building it: " << errmsg << ' ' << tabletoidxns << ' ' << name << endl;
}
- raiseError(saveerrmsg.c_str());
+ raiseError(12506,saveerrmsg.c_str());
throw;
}
}
View
7 jstests/error4.js
@@ -0,0 +1,7 @@
+
+t = db.error4;
+t.drop()
+t.insert( { _id : 1 } )
+t.insert( { _id : 1 } )
+assert.eq( 11000 , db.getLastErrorCmd().code , "A" )
+
View
10 util/assert_util.cpp
@@ -30,14 +30,14 @@ namespace mongo {
void wasserted(const char *msg, const char *file, unsigned line) {
problem() << "Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl;
sayDbContext();
- raiseError(msg && *msg ? msg : "wassertion failure");
+ raiseError(0,msg && *msg ? msg : "wassertion failure");
lastAssert[1].set(msg, getDbContext().c_str(), file, line);
}
void asserted(const char *msg, const char *file, unsigned line) {
problem() << "Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl;
sayDbContext();
- raiseError(msg && *msg ? msg : "assertion failure");
+ raiseError(0,msg && *msg ? msg : "assertion failure");
lastAssert[0].set(msg, getDbContext().c_str(), file, line);
stringstream temp;
temp << "assertion " << file << ":" << line;
@@ -49,7 +49,7 @@ namespace mongo {
void uassert_nothrow(const char *msg) {
lastAssert[3].set(msg, getDbContext().c_str(), "", 0);
- raiseError(msg);
+ raiseError(0,msg);
}
int uacount = 0;
@@ -59,14 +59,14 @@ namespace mongo {
else
RARELY log() << "User Exception " << msg << endl;
lastAssert[3].set(msg, getDbContext().c_str(), "", 0);
- raiseError(msg);
+ raiseError(msgid,msg);
throw UserException(msgid, msg);
}
void msgasserted(int msgid, const char *msg) {
log() << "Assertion: " << msgid << ":" << msg << endl;
lastAssert[2].set(msg, getDbContext().c_str(), "", 0);
- raiseError(msg && *msg ? msg : "massert failure");
+ raiseError(msgid,msg && *msg ? msg : "massert failure");
breakpoint();
printStackTrace(); // TEMP?? should we get rid of this? TODO
throw MsgAssertionException(msgid, msg);
Please sign in to comment.
Something went wrong with that request. Please try again.