summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authordaveh86 <howsdav@gmail.com>2014-05-14 19:43:38 -0400
committerBenety Goh <benety@mongodb.com>2014-05-22 09:17:09 -0400
commit0e224f9a0fe0a37ee2b22c0a0ba20ec2a1f48aeb (patch)
tree4e7cbbd2f720c6e21a35b8d1b4d493522fbd8291 /src/mongo/shell
parent885e11b64dae39b4a90304e754caa26254442180 (diff)
downloadmongo-0e224f9a0fe0a37ee2b22c0a0ba20ec2a1f48aeb.tar.gz
SERVER-10177 Remove all Js instances of "throw 'string';" with "throw Error();"
Includes both the initial patch to remove all throws and patches for all failing tests Signed-off-by: Benety Goh <benety@mongodb.com>
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/collection.js48
-rw-r--r--src/mongo/shell/db.js34
-rw-r--r--src/mongo/shell/mongo.js14
-rw-r--r--src/mongo/shell/query.js12
-rwxr-xr-xsrc/mongo/shell/servers.js4
-rw-r--r--src/mongo/shell/shardingtest.js20
-rw-r--r--src/mongo/shell/types.js6
-rw-r--r--src/mongo/shell/utils.js4
-rw-r--r--src/mongo/shell/utils_sh.js10
9 files changed, 76 insertions, 76 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index c9472fb8078..a895fb6f704 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -127,7 +127,7 @@ DBCollection.prototype._massageObject = function( q ){
return { $where : q };
}
- throw "don't know how to massage : " + type;
+ throw Error( "don't know how to massage : " + type );
}
@@ -137,10 +137,10 @@ DBCollection.prototype._validateObject = function( o ){
if (this.getMongo()._skipValidation) return;
if (typeof(o) != "object")
- throw "attempted to save a " + typeof(o) + " value. document expected.";
+ throw Error( "attempted to save a " + typeof(o) + " value. document expected." );
if ( o._ensureSpecial && o._checkModify )
- throw "can't save a DBQuery object";
+ throw Error( "can't save a DBQuery object" );
}
DBCollection._allowedFields = { $id : 1 , $ref : 1 , $db : 1 };
@@ -152,11 +152,11 @@ DBCollection.prototype._validateForStorage = function( o ){
this._validateObject( o );
for ( var k in o ){
if ( k.indexOf( "." ) >= 0 ) {
- throw "can't have . in field names [" + k + "]" ;
+ throw Error( "can't have . in field names [" + k + "]" );
}
if ( k.indexOf( "$" ) == 0 && ! DBCollection._allowedFields[k] ) {
- throw "field names cannot start with $ [" + k + "]";
+ throw Error( "field names cannot start with $ [" + k + "]" );
}
if ( o[k] !== null && typeof( o[k] ) === "object" ) {
@@ -185,15 +185,15 @@ DBCollection.prototype.findOne = function( query , fields, options ){
if ( ! cursor.hasNext() )
return null;
var ret = cursor.next();
- if ( cursor.hasNext() ) throw "findOne has more than 1 result!";
+ if ( cursor.hasNext() ) throw Error( "findOne has more than 1 result!" );
if ( ret.$err )
- throw "error " + tojson( ret );
+ throw Error( "error " + tojson( ret ) );
return ret;
}
DBCollection.prototype.insert = function( obj , options, _allow_dot ){
if ( ! obj )
- throw "no object passed to insert!";
+ throw Error( "no object passed to insert!" );
var flags = 0;
@@ -255,7 +255,7 @@ DBCollection.prototype.insert = function( obj , options, _allow_dot ){
}
else {
// Other exceptions thrown
- throw ex;
+ throw Error(ex);
}
}
}
@@ -296,7 +296,7 @@ DBCollection.prototype._validateRemoveDoc = function(doc) {
};
DBCollection.prototype.remove = function( t , justOne ){
- if (t == undefined) throw "remove needs a query";
+ if (t == undefined) throw Error("remove needs a query");
var result = undefined;
var startTime = (typeof(_verboseShell) === 'undefined' ||
!_verboseShell) ? 0 : new Date().getTime();
@@ -332,7 +332,7 @@ DBCollection.prototype.remove = function( t , justOne ){
}
else {
// Other exceptions thrown
- throw ex;
+ throw Error(ex);
}
}
}
@@ -413,7 +413,7 @@ DBCollection.prototype.update = function( query , obj , upsert , multi ){
}
else {
// Other exceptions thrown
- throw ex;
+ throw Error(ex);
}
}
}
@@ -433,10 +433,10 @@ DBCollection.prototype.update = function( query , obj , upsert , multi ){
DBCollection.prototype.save = function( obj , opts ){
if ( obj == null )
- throw "can't save a null";
+ throw Error("can't save a null");
if ( typeof( obj ) == "number" || typeof( obj) == "string" )
- throw "can't save a number or string"
+ throw Error("can't save a number or string");
if ( typeof( obj._id ) == "undefined" ){
obj._id = new ObjectId();
@@ -494,7 +494,7 @@ DBCollection.prototype._indexSpec = function( keys, options ) {
}
}
else {
- throw "can't handle: " + typeof( options );
+ throw Error( "can't handle: " + typeof( options ) );
}
/*
return ret;
@@ -574,7 +574,7 @@ DBCollection.prototype.reIndex = function() {
DBCollection.prototype.dropIndexes = function(){
if ( arguments.length )
- throw "dropIndexes doesn't take arguments";
+ throw Error("dropIndexes doesn't take arguments");
var res = this._db.runCommand( { deleteIndexes: this.getName(), index: "*" } );
assert( res , "no result from dropIndex result" );
@@ -584,18 +584,18 @@ DBCollection.prototype.dropIndexes = function(){
if ( res.errmsg.match( /not found/ ) )
return res;
- throw "error dropping indexes : " + tojson( res );
+ throw Error( "error dropping indexes : " + tojson( res ) );
}
DBCollection.prototype.drop = function(){
if ( arguments.length > 0 )
- throw "drop takes no argument";
+ throw Error("drop takes no argument");
var ret = this._db.runCommand( { drop: this.getName() } );
if ( ! ret.ok ){
if ( ret.errmsg == "ns not found" )
return false;
- throw "drop failed: " + tojson( ret );
+ throw Error( "drop failed: " + tojson( ret ) );
}
return true;
}
@@ -611,7 +611,7 @@ DBCollection.prototype.findAndModify = function(args){
if (ret.errmsg == "No matching object found"){
return null;
}
- throw "findAndModifyFailed failed: " + tojson( ret );
+ throw Error( "findAndModifyFailed failed: " + tojson( ret ) );
}
return ret.value;
}
@@ -1082,7 +1082,7 @@ DBCollection.prototype.totalSize = function(){
DBCollection.prototype.convertToCapped = function( bytes ){
if ( ! bytes )
- throw "have to specify # of bytes";
+ throw Error("have to specify # of bytes");
return this._dbCommand( { convertToCapped : this._shortName , size : bytes } )
}
@@ -1098,14 +1098,14 @@ DBCollection.prototype.isCapped = function(){
DBCollection.prototype._distinct = function( keyString , query ){
return this._dbCommand( { distinct : this._shortName , key : keyString , query : query || {} } );
if ( ! res.ok )
- throw "distinct failed: " + tojson( res );
+ throw Error( "distinct failed: " + tojson( res ) );
return res.values;
}
DBCollection.prototype.distinct = function( keyString , query ){
var res = this._distinct( keyString , query );
if ( ! res.ok )
- throw "distinct failed: " + tojson( res );
+ throw Error( "distinct failed: " + tojson( res ) );
return res.values;
}
@@ -1221,7 +1221,7 @@ DBCollection.prototype.mapReduce = function( map , reduce , optionsOrOutString )
var raw = this._db.runCommand( c );
if ( ! raw.ok ){
__mrerror__ = raw;
- throw "map reduce failed:" + tojson(raw);
+ throw Error( "map reduce failed:" + tojson(raw) );
}
return new MapReduceResult( this._db , raw );
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index 3a714b3a984..e4b2daab0ad 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 res.errmsg;
+ throw Error(res.errmsg);
return res.help;
}
@@ -125,7 +125,7 @@ DB.prototype.getProfilingLevel = function() {
DB.prototype.getProfilingStatus = function() {
var res = this._dbCommand( { profile: -1 } );
if ( ! res.ok )
- throw "profile command failed: " + tojson( res );
+ throw Error( "profile command failed: " + tojson( res ) );
delete res.ok
return res;
}
@@ -138,7 +138,7 @@ DB.prototype.getProfilingStatus = function() {
*/
DB.prototype.dropDatabase = function() {
if ( arguments.length )
- throw "dropDatabase doesn't take arguments";
+ throw Error("dropDatabase doesn't take arguments");
return this._dbCommand( { dropDatabase: 1 } );
}
@@ -164,8 +164,8 @@ DB.prototype.shutdownServer = function(opts) {
try {
var res = this.runCommand(cmd);
if( res )
- throw "shutdownServer failed: " + res.errmsg;
- throw "shutdownServer failed";
+ throw Error( "shutdownServer failed: " + res.errmsg );
+ throw Error( "shutdownServer failed" );
}
catch ( e ){
assert( tojson( e ).indexOf( "error doing query: failed" ) >= 0 , "unexpected error: " + tojson( e ) );
@@ -399,7 +399,7 @@ DB.prototype.eval = function(jsfunction) {
var res = this._dbCommand( cmd );
if (!res.ok)
- throw tojson( res );
+ throw Error( tojson( res ) );
return res.retval;
}
@@ -483,7 +483,7 @@ DB.prototype.groupeval = function(parmsObj) {
DB.prototype.groupcmd = function( parmsObj ){
var ret = this.runCommand( { "group" : this._groupFixParms( parmsObj ) } );
if ( ! ret.ok ){
- throw "group command failed: " + tojson( ret );
+ throw Error( "group command failed: " + tojson( ret ) );
}
return ret.retval;
}
@@ -517,7 +517,7 @@ DB.prototype.forceError = function(){
DB.prototype.getLastError = function( w , wtimeout ){
var res = this.getLastErrorObj( w , wtimeout );
if ( ! res.ok )
- throw "getlasterror failed: " + tojson( res );
+ throw Error( "getlasterror failed: " + tojson( res ) );
return res.err;
}
DB.prototype.getLastErrorObj = function( w , wtimeout ){
@@ -530,7 +530,7 @@ DB.prototype.getLastErrorObj = function( w , wtimeout ){
var res = this.runCommand( cmd );
if ( ! res.ok )
- throw "getlasterror failed: " + tojson( res );
+ throw Error( "getlasterror failed: " + tojson( res ) );
return res;
}
DB.prototype.getLastErrorCmd = DB.prototype.getLastErrorObj;
@@ -589,7 +589,7 @@ DB.prototype.currentOP = DB.prototype.currentOp;
DB.prototype.killOp = function(op) {
if( !op )
- throw "no opNum to kill specified";
+ throw Error("no opNum to kill specified");
return this.$cmd.sys.killop.findOne({'op':op});
}
DB.prototype.killOP = DB.prototype.killOp;
@@ -880,7 +880,7 @@ DB.prototype._addUserWithInsert = function(userObj, replicatedTo, timeout) {
print( "Creating user seems to have succeeded but threw an exception because we no " +
"longer have auth." );
} else {
- throw "Could not insert into system.users: " + tojson(e);
+ throw Error( "Could not insert into system.users: " + tojson(e) );
}
}
print("Successfully added user: " + getUserObjString(userObj));
@@ -922,15 +922,15 @@ DB.prototype._addUserWithInsert = function(userObj, replicatedTo, timeout) {
}
if (le.err == "timeout") {
- throw "timed out while waiting for user authentication to replicate - " +
- "database will not be fully secured until replication finishes"
+ throw Error( "timed out while waiting for user authentication to replicate - " +
+ "database will not be fully secured until replication finishes" )
}
if (le.err.startsWith("E11000 duplicate key error")) {
- throw "User already exists with that username/userSource combination";
+ throw Error("User already exists with that username/userSource combination");
}
- throw "couldn't add user: " + le.err;
+ throw Error( "couldn't add user: " + le.err );
}
/**
@@ -1017,7 +1017,7 @@ function _hashPassword(username, password) {
// TODO(spencer): remove this form from v2.8
DB.prototype._addUserDeprecatedV22Version = function(username, pass, readOnly, replicatedTo, timeout) {
if ( pass == null || pass.length == 0 )
- throw "password can't be empty";
+ throw Error("password can't be empty");
var userObjForCommand = { user: username, pwd: pass };
if (this.getName() == "admin") {
@@ -1153,7 +1153,7 @@ DB.prototype._removeUserV1 = function(username, writeConcern) {
var le = db.getLastErrorObj(writeConcern['w'], writeConcern['wtimeout']);
if (le.err) {
- throw "Couldn't remove user: " + le.err;
+ throw Error( "Couldn't remove user: " + le.err );
}
if (le.n == 1) {
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 422598ecad1..df8d825c4d5 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -8,17 +8,17 @@ if ( typeof Mongo == "undefined" ){
}
if ( ! Mongo.prototype ){
- throw "Mongo.prototype not defined";
+ throw Error("Mongo.prototype not defined");
}
if ( ! Mongo.prototype.find )
- Mongo.prototype.find = function( ns , query , fields , limit , skip , batchSize , options ){ throw "find not implemented"; }
+ Mongo.prototype.find = function( ns , query , fields , limit , skip , batchSize , options ){ throw Error("find not implemented"); }
if ( ! Mongo.prototype.insert )
- Mongo.prototype.insert = function( ns , obj ){ throw "insert not implemented"; }
+ Mongo.prototype.insert = function( ns , obj ){ throw Error("insert not implemented"); }
if ( ! Mongo.prototype.remove )
- Mongo.prototype.remove = function( ns , pattern ){ throw "remove not implemented;" }
+ Mongo.prototype.remove = function( ns , pattern ){ throw Error("remove not implemented"); }
if ( ! Mongo.prototype.update )
- Mongo.prototype.update = function( ns , query , obj , upsert ){ throw "update not implemented;" }
+ Mongo.prototype.update = function( ns , query , obj , upsert ){ throw Error("update not implemented"); }
if ( typeof mongoInject == "function" ){
mongoInject( Mongo.prototype );
@@ -44,7 +44,7 @@ Mongo.prototype.getDB = function( name ){
Mongo.prototype.getDBs = function(){
var res = this.getDB( "admin" ).runCommand( { "listDatabases" : 1 } );
if ( ! res.ok )
- throw "listDatabases failed:" + tojson( res );
+ throw Error( "listDatabases failed:" + tojson( res ) );
return res;
}
@@ -67,7 +67,7 @@ Mongo.prototype.getDBNames = function(){
Mongo.prototype.getCollection = function(ns){
var idx = ns.indexOf( "." );
if ( idx < 0 )
- throw "need . in ns";
+ throw Error("need . in ns");
var db = ns.substring( 0 , idx );
var c = ns.substring( idx + 1 );
return this.getDB( db ).getCollection( c );
diff --git a/src/mongo/shell/query.js b/src/mongo/shell/query.js
index 6633c88bfac..8e8613fcd86 100644
--- a/src/mongo/shell/query.js
+++ b/src/mongo/shell/query.js
@@ -74,7 +74,7 @@ DBQuery.prototype._ensureSpecial = function(){
DBQuery.prototype._checkModify = function(){
if ( this._cursor )
- throw "query already executed";
+ throw Error("query already executed");
}
DBQuery.prototype._exec = function(){
@@ -126,11 +126,11 @@ DBQuery.prototype.next = function(){
if ( o )
this._cursorSeen++;
else
- throw "error hasNext: " + o;
+ throw Error( "error hasNext: " + o );
var ret = this._cursor.next();
if ( ret.$err )
- throw "error: " + tojson( ret );
+ throw Error( "error: " + tojson( ret ) );
this._numReturned++;
return ret;
@@ -141,7 +141,7 @@ DBQuery.prototype.objsLeftInBatch = function(){
var ret = this._cursor.objsLeftInBatch();
if ( ret.$err )
- throw "error: " + tojson( ret );
+ throw Error( "error: " + tojson( ret ) );
return ret;
}
@@ -190,7 +190,7 @@ DBQuery.prototype.count = function( applySkipLimit ) {
var res = this._db.runCommand( cmd );
if( res && res.n != null ) return res.n;
- throw "count failed: " + tojson( res );
+ throw Error( "count failed: " + tojson( res ) );
}
DBQuery.prototype.size = function(){
@@ -416,7 +416,7 @@ DBCommandCursor.prototype.next = function() {
else {
var ret = this._cursor.next();
if ( ret.$err )
- throw "error: " + tojson( ret );
+ throw Error( "error: " + tojson( ret ) );
return ret;
}
}
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 145cdaf0c9a..794d5484c21 100755
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -8,7 +8,7 @@ _parsePath = function() {
dbpath = arguments[ i + 1 ];
if ( dbpath == "" )
- throw "No dbpath specified";
+ throw Error("No dbpath specified");
return dbpath;
}
@@ -20,7 +20,7 @@ _parsePort = function() {
port = arguments[ i + 1 ];
if ( port == "" )
- throw "No port specified";
+ throw Error("No port specified");
return port;
}
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index d3e98245319..6f74762856e 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -288,7 +288,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
this._configNames = []
if ( otherParams.sync && ! otherParams.separateConfig && numShards < 3 )
- throw "if you want sync, you need at least 3 servers";
+ throw Error("if you want sync, you need at least 3 servers");
for ( var i = 0; i < ( otherParams.sync ? 3 : 1 ) ; i++ ) {
@@ -336,7 +336,7 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
if ( numMongos == 0 && !otherParams.noChunkSize ) {
if ( keyFile ) {
- throw "Cannot set chunk size without any mongos when using auth";
+ throw Error("Cannot set chunk size without any mongos when using auth");
} else {
this._configConnection.getDB( "config" ).settings.insert(
{ _id : "chunksize" , value : otherParams.chunksize || otherParams.chunkSize || 50 } );
@@ -416,7 +416,7 @@ ShardingTest.prototype.getRSEntry = function( setName ){
for ( var i=0; i<this._rs.length; i++ )
if ( this._rs[i].setName == setName )
return this._rs[i];
- throw "can't find rs: " + setName;
+ throw Error( "can't find rs: " + setName );
}
ShardingTest.prototype.getConfigIndex = function( config ){
@@ -440,7 +440,7 @@ ShardingTest.prototype.getServerName = function( dbname ){
if ( x )
return x.primary;
this.config.databases.find().forEach( printjson );
- throw "couldn't find dbname: " + dbname + " total: " + this.config.databases.count();
+ throw Error( "couldn't find dbname: " + dbname + " total: " + this.config.databases.count() );
}
@@ -448,7 +448,7 @@ ShardingTest.prototype.getNonPrimaries = function( dbname ){
var x = this.config.databases.findOne( { _id : dbname } );
if ( ! x ){
this.config.databases.find().forEach( printjson );
- throw "couldn't find dbname: " + dbname + " total: " + this.config.databases.count();
+ throw Error( "couldn't find dbname: " + dbname + " total: " + this.config.databases.count() );
}
return this.config.shards.find( { _id : { $ne : x.primary } } ).map( function(z){ return z._id; } )
@@ -481,7 +481,7 @@ ShardingTest.prototype.getServer = function( dbname ){
return c;
}
- throw "can't find server for: " + dbname + " name:" + name;
+ throw Error( "can't find server for: " + dbname + " name:" + name );
}
@@ -494,7 +494,7 @@ ShardingTest.prototype.normalize = function( x ){
ShardingTest.prototype.getOther = function( one ){
if ( this._connections.length < 2 )
- throw "getOther only works with 2 servers";
+ throw Error("getOther only works with 2 servers");
if ( one._mongo )
one = one._mongo
@@ -508,7 +508,7 @@ ShardingTest.prototype.getOther = function( one ){
ShardingTest.prototype.getAnother = function( one ){
if(this._connections.length < 2)
- throw "getAnother() only works with multiple servers";
+ throw Error("getAnother() only works with multiple servers");
if ( one._mongo )
one = one._mongo
@@ -524,7 +524,7 @@ ShardingTest.prototype.getFirstOther = function( one ){
if ( this._connections[i] != one )
return this._connections[i];
}
- throw "impossible";
+ throw Error("impossible");
}
ShardingTest.prototype.stop = function(){
@@ -560,7 +560,7 @@ ShardingTest.prototype.adminCommand = function(cmd){
if ( res && res.ok == 1 )
return true;
- throw "command " + tojson( cmd ) + " failed: " + tojson( res );
+ throw Error( "command " + tojson( cmd ) + " failed: " + tojson( res ) );
}
ShardingTest.prototype._rangeToString = function(r){
diff --git a/src/mongo/shell/types.js b/src/mongo/shell/types.js
index 4a1eaf8bde4..2b351e36bd7 100644
--- a/src/mongo/shell/types.js
+++ b/src/mongo/shell/types.js
@@ -61,7 +61,7 @@ ISODate = function(isoDateStr){
var res = isoDateRegex.exec(isoDateStr);
if (!res)
- throw "invalid ISO date";
+ throw Error("invalid ISO date");
var year = parseInt(res[1],10) || 1970; // this should always be present
var month = (parseInt(res[2],10) || 1) - 1;
@@ -455,7 +455,7 @@ Map.hash = function(val){
return s;
}
- throw "can't hash : " + typeof(val);
+ throw Error( "can't hash : " + typeof(val) );
}
Map.prototype.put = function(key, value){
@@ -570,7 +570,7 @@ tojson = function(x, indent, nolint){
case "function":
return x.toString();
default:
- throw "tojson can't handle type " + (typeof x);
+ throw Error( "tojson can't handle type " + (typeof x) );
}
}
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 9006582a819..41998b352ab 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -515,7 +515,7 @@ shellHelper = function( command , rest , shouldPrint ){
var args = rest.trim().replace(/\s*;$/,"").split( "\s+" );
if ( ! shellHelper[command] )
- throw "no command [" + command + "]";
+ throw Error( "no command [" + command + "]" );
var res = shellHelper[command].apply( null , args );
if ( shouldPrint ){
@@ -726,7 +726,7 @@ shellHelper.show = function (what) {
}
}
- throw "don't know how to show [" + what + "]";
+ throw Error( "don't know how to show [" + what + "]" );
}
diff --git a/src/mongo/shell/utils_sh.js b/src/mongo/shell/utils_sh.js
index c567e2dee5a..ae1a8694ed7 100644
--- a/src/mongo/shell/utils_sh.js
+++ b/src/mongo/shell/utils_sh.js
@@ -3,7 +3,7 @@ sh = function() { return "try sh.help();" }
sh._checkMongos = function() {
var x = db.runCommand( "ismaster" );
if ( x.msg != "isdbgrid" )
- throw "not connected to a mongos"
+ throw Error("not connected to a mongos");
}
sh._checkFullName = function( fullName ) {
@@ -225,7 +225,7 @@ sh.waitForBalancerOff = function( timeout, interval ){
}
catch( e ){
print( "Balancer still may be active, you must manually verify this is not the case using the config.changelog collection." )
- throw e
+ throw Error(e);
}
print( "Waiting again for active hosts after balancer is off..." )
@@ -319,13 +319,13 @@ sh._lastMigration = function( ns ){
sh._checkLastError = function( mydb ) {
var err = mydb.getLastError();
if ( err )
- throw "error: " + err;
+ throw Error( "error: " + err );
}
sh.addShardTag = function( shard, tag ) {
var config = db.getSisterDB( "config" );
if ( config.shards.findOne( { _id : shard } ) == null ) {
- throw "can't find a shard with name: " + shard;
+ throw Error( "can't find a shard with name: " + shard );
}
config.shards.update( { _id : shard } , { $addToSet : { tags : tag } } );
sh._checkLastError( config );
@@ -334,7 +334,7 @@ sh.addShardTag = function( shard, tag ) {
sh.removeShardTag = function( shard, tag ) {
var config = db.getSisterDB( "config" );
if ( config.shards.findOne( { _id : shard } ) == null ) {
- throw "can't find a shard with name: " + shard;
+ throw Error( "can't find a shard with name: " + shard );
}
config.shards.update( { _id : shard } , { $pull : { tags : tag } } );
sh._checkLastError( config );