-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Internal Code, JavaScript, Shell
-
Minor Change
Currently we throw with strings in js code (collection/db/query/mongo/etc) when we have an object/bsonobj. We should simply build a wrapper object and throw that.
$ grep -i throw.*tojson\( src/mongo/shell/*.js src/mongo/shell/collection.js: throw "error " + tojson( ret ); src/mongo/shell/collection.js: throw "error dropping indexes : " + tojson( res ); src/mongo/shell/collection.js: throw "drop failed: " + tojson( ret ); src/mongo/shell/collection.js: throw "findAndModifyFailed failed: " + tojson( ret ); src/mongo/shell/collection.js: throw "distinct failed: " + tojson( res ); src/mongo/shell/collection.js: throw "distinct failed: " + tojson( res ); src/mongo/shell/collection.js: throw "aggregate failed: " + tojson(res); src/mongo/shell/collection.js: throw "map reduce failed:" + tojson(raw); src/mongo/shell/db.js: throw "Could not insert into system.users: " + tojson(e); src/mongo/shell/db.js: throw "profile command failed: " + tojson( res ); src/mongo/shell/db.js: throw tojson( res ); src/mongo/shell/db.js: throw "group command failed: " + tojson( ret ); src/mongo/shell/db.js: throw "getlasterror failed: " + tojson( res ); src/mongo/shell/db.js: throw "getlasterror failed: " + tojson( res ); src/mongo/shell/mongo.js: throw "listDatabases failed:" + tojson( res ); src/mongo/shell/query.js: throw "error: " + tojson( ret ); src/mongo/shell/query.js: throw "error: " + tojson( ret ); src/mongo/shell/query.js: throw "count failed: " + tojson( res ); src/mongo/shell/query.js: throw "error: " + tojson( ret ); src/mongo/shell/shardingtest.js: throw "command " + tojson( cmd ) + " failed: " + tojson( res );
In addition to these we should fix all "throw <string>" instances to throw "Error(<string>)".
- duplicates
-
SERVER-10177 Javascript code should throw instances of Error instead of strings.
- Closed