Skip to content

Commit

Permalink
use code in getLastError SERVER-112
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Dec 28, 2009
1 parent fa8961c commit d5a5401
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
3 changes: 1 addition & 2 deletions buildscripts/errorcodes.py
Expand Up @@ -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() ) )

2 changes: 2 additions & 0 deletions db/lasterror.cpp
Expand Up @@ -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 );
Expand Down
9 changes: 6 additions & 3 deletions db/lasterror.h
Expand Up @@ -26,15 +26,17 @@ namespace mongo {
class Message;

struct LastError {
int code;
string msg;
enum UpdatedExistingType { NotUpdate, True, False } updatedExisting;
/* todo: nObjects should be 64 bit */
int nObjects;
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 ) {
Expand All @@ -51,6 +53,7 @@ namespace mongo {
reset();
}
void reset( bool _valid = false ) {
code = 0;
msg.clear();
updatedExisting = NotUpdate;
nObjects = 0;
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion db/pdfile.cpp
Expand Up @@ -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;
}
}
Expand Down
7 changes: 7 additions & 0 deletions 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" )

10 changes: 5 additions & 5 deletions util/assert_util.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit d5a5401

Please sign in to comment.