[SERVER-10177] Javascript code should throw instances of Error instead of strings. Created: 11/Jul/13  Updated: 04/Sep/14  Resolved: 23/May/14

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

Type: Improvement Priority: Major - P3
Reporter: Andy Schwerin Assignee: David Hows
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-10178 Print js stack traces when exceptions... Closed
Duplicate
is duplicated by SERVER-10185 Throw objects not strings Closed
Sprint: Server 2.7.1
Participants:

 Description   

Instances of Error have a stack trace in addition to a message, which could then be printed if the exception reaches the top of the call stack. Presently, the MongoDB javascript code in the shell and in the server throws a mix of strings and Errors.



 Comments   
Comment by Githook User [ 22/May/14 ]

Author:

{u'username': u'daveh86', u'name': u'daveh86', u'email': u'howsdav@gmail.com'}

Message: 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>
Branch: master
https://github.com/mongodb/mongo/commit/0e224f9a0fe0a37ee2b22c0a0ba20ec2a1f48aeb

Comment by Andy Schwerin [ 01/May/14 ]

Run the following "grep" from a shell at the root of the git repo to find many/all guilty lines. Around 90 as of 2014-May-01.

grep --include="*.js" -IrE 'throw *["'"'"'0-9]' jstests src/mongo

Comment by Eric Daniels (Inactive) [ 25/Jul/13 ]

Had to assign self to stop progress

Comment by auto [ 20/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-10270 SERVER-10177 Fix failing jstests/apitest_db.js

Restore the exception object field that the test is looking for.
Branch: master
https://github.com/mongodb/mongo/commit/14e3de5ca929ef3187768146c7bf6a102f56db1f

Comment by auto [ 19/Jul/13 ]

Author:

{u'username': u'monkey101', u'name': u'Dan Pasette', u'email': u'dan@10gen.com'}

Message: SERVER-10177 Fix dbSetProfilingLevel() error message when level is out of range.
Branch: master
https://github.com/mongodb/mongo/commit/04469544920312ead0bd1a85b1f2d26a4bc4f52d

Comment by Scott Hernandez (Inactive) [ 11/Jul/13 ]

For things with structured data, like bson from the server, we can write a helper to attach the embedded object/bson like so:

function ErrorWithObj(obj) {
   var err = Error(tojson(obj));
   err.obj = obj;
   return err;
}
function ErrorWithObjDesc(desc, obj) {
   var err = Error(desc);
   err.obj = obj;
   return err;
}

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