[SERVER-10185] Throw objects not strings Created: 11/Jul/13  Updated: 14/May/14  Resolved: 11/Jul/13

Status: Closed
Project: Core Server
Component/s: Internal Code, JavaScript, Shell
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-10177 Javascript code should throw instance... Closed
Backwards Compatibility: Minor Change
Participants:

 Description   

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>)".


Generated at Thu Feb 08 03:22:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.