diff options
Diffstat (limited to 'src/mongo/shell/db.js')
-rw-r--r-- | src/mongo/shell/db.js | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 2e0755d703f..2cecf28e579 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -40,7 +40,7 @@ DB.prototype.commandHelp = function( name ){ c.help = true; var res = this.runCommand( c ); if ( ! res.ok ) - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); return res.help; } @@ -238,7 +238,7 @@ DB.prototype.getProfilingLevel = function() { DB.prototype.getProfilingStatus = function() { var res = this._dbCommand( { profile: -1 } ); if ( ! res.ok ) - throw Error( "profile command failed: " + tojson( res ) ); + throw _getErrorWithCode(res, "profile command failed: " + tojson(res)); delete res.ok return res; } @@ -277,7 +277,7 @@ DB.prototype.shutdownServer = function(opts) { try { var res = this.runCommand(cmd); if (!res.ok) { - throw Error('shutdownServer failed: ' + tojson(res)); + throw _getErrorWithCode(res, 'shutdownServer failed: ' + tojson(res)); } throw Error('shutdownServer failed: server is still up.'); } @@ -539,7 +539,7 @@ DB.prototype.eval = function(jsfunction) { var res = this._dbCommand( cmd ); if (!res.ok) - throw Error( tojson( res ) ); + throw _getErrorWithCode(res, tojson(res)); return res.retval; } @@ -623,7 +623,7 @@ DB.prototype.groupeval = function(parmsObj) { DB.prototype.groupcmd = function( parmsObj ){ var ret = this.runCommand( { "group" : this._groupFixParms( parmsObj ) } ); if ( ! ret.ok ){ - throw Error( "group command failed: " + tojson( ret ) ); + throw _getErrorWithCode(ret, "group command failed: " + tojson(ret)); } return ret.retval; } @@ -657,7 +657,7 @@ DB.prototype.forceError = function(){ DB.prototype.getLastError = function( w , wtimeout ){ var res = this.getLastErrorObj( w , wtimeout ); if ( ! res.ok ) - throw Error( "getlasterror failed: " + tojson( res ) ); + throw _getErrorWithCode(ret, "getlasterror failed: " + tojson(res)); return res.err; } DB.prototype.getLastErrorObj = function( w , wtimeout ){ @@ -670,7 +670,7 @@ DB.prototype.getLastErrorObj = function( w , wtimeout ){ var res = this.runCommand( cmd ); if ( ! res.ok ) - throw Error( "getlasterror failed: " + tojson( res ) ); + throw _getErrorWithCode(res, "getlasterror failed: " + tojson(res)); return res; } DB.prototype.getLastErrorCmd = DB.prototype.getLastErrorObj; @@ -732,7 +732,7 @@ DB.prototype._getCollectionInfosCommand = function(filter) { return null; } - throw Error( "listCollections failed: " + tojson( res ) ); + throw _getErrorWithCode(res, "listCollections failed: " + tojson(res)); } // The listCollections command returns its results sorted by collection name. There's no need @@ -1210,7 +1210,7 @@ DB.prototype.createUser = function(userObj, writeConcern) { "database will not be fully secured until replication finishes"); } - throw Error("couldn't add user: " + res.errmsg); + throw _getErrorWithCode(res, "couldn't add user: " + res.errmsg); } function _hashPassword(username, password) { @@ -1239,9 +1239,9 @@ DB.prototype._updateUserV1 = function(name, updateObject, writeConcern) { this.system.users.update({user : name, userSource : null}, {$set : setObj}); - var err = this.getLastError(writeConcern['w'], writeConcern['wtimeout']); - if (err) { - throw Error("Updating user failed: " + err); + var errObj = this.getLastErrorObj(writeConcern['w'], writeConcern['wtimeout']); + if (errObj.err) { + throw _getErrorWithCode(errObj, "Updating user failed: " + errObj.err); } }; @@ -1261,7 +1261,7 @@ DB.prototype.updateUser = function(name, updateObject, writeConcern) { return; } - throw Error("Updating user failed: " + res.errmsg); + throw _getErrorWithCode(res, "Updating user failed: " + res.errmsg); }; DB.prototype.changeUserPassword = function(username, password, writeConcern) { @@ -1295,7 +1295,7 @@ DB.prototype.dropUser = function( username, writeConcern ){ return this._removeUserV1(username, cmdObj['writeConcern']); } - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } /** @@ -1308,7 +1308,7 @@ DB.prototype._removeUserV1 = function(username, writeConcern) { var le = this.getLastErrorObj(writeConcern['w'], writeConcern['wtimeout']); if (le.err) { - throw Error( "Couldn't remove user: " + le.err ); + throw _getErrorWithCode(le, "Couldn't remove user: " + le.err); } if (le.n == 1) { @@ -1323,7 +1323,7 @@ DB.prototype.dropAllUsers = function(writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } return res.n; @@ -1407,7 +1407,7 @@ DB.prototype.grantRolesToUser = function(username, roles, writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1417,7 +1417,7 @@ DB.prototype.revokeRolesFromUser = function(username, roles, writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1430,7 +1430,7 @@ DB.prototype.getUser = function(username, args) { var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } if (res.users.length == 0) { @@ -1451,7 +1451,7 @@ DB.prototype.getUsers = function(args) { return this.system.users.find({}).toArray(); } - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } return res.users; @@ -1467,7 +1467,7 @@ DB.prototype.createRole = function(roleObj, writeConcern) { var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } printjson(roleObj); } @@ -1478,7 +1478,7 @@ DB.prototype.updateRole = function(name, updateObject, writeConcern) { cmdObj['writeConcern'] = writeConcern ? writeConcern : _defaultWriteConcern; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } }; @@ -1495,7 +1495,7 @@ DB.prototype.dropRole = function(name, writeConcern) { return false; } - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); }; DB.prototype.dropAllRoles = function(writeConcern) { @@ -1503,7 +1503,7 @@ DB.prototype.dropAllRoles = function(writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } return res.n; @@ -1515,7 +1515,7 @@ DB.prototype.grantRolesToRole = function(rolename, roles, writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1525,7 +1525,7 @@ DB.prototype.revokeRolesFromRole = function(rolename, roles, writeConcern) { writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1535,7 +1535,7 @@ DB.prototype.grantPrivilegesToRole = function(rolename, privileges, writeConcern writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1545,7 +1545,7 @@ DB.prototype.revokePrivilegesFromRole = function(rolename, privileges, writeConc writeConcern: writeConcern ? writeConcern : _defaultWriteConcern}; var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } } @@ -1557,7 +1557,7 @@ DB.prototype.getRole = function(rolename, args) { Object.extend(cmdObj, args); var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } if (res.roles.length == 0) { @@ -1571,7 +1571,7 @@ DB.prototype.getRoles = function(args) { Object.extend(cmdObj, args); var res = this.runCommand(cmdObj); if (!res.ok) { - throw Error(res.errmsg); + throw _getErrorWithCode(res, res.errmsg); } return res.roles; |