summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-04-08 12:11:34 -0400
committerAaron <aaron@10gen.com>2009-04-08 12:11:34 -0400
commit78625e7616ee39b19bbde08744a7550c8a424d07 (patch)
tree5f59391f4ec3a6e34034f79de9a81a404a934162
parent94e12ec06b6e784f319a23e77921cd3ce28918f9 (diff)
downloadmongo-78625e7616ee39b19bbde08744a7550c8a424d07.tar.gz
forward stack trace to client when $where throws exception
-rw-r--r--db/matcher.cpp11
-rw-r--r--jstests/error2.js20
-rw-r--r--mongo.xcodeproj/project.pbxproj2
3 files changed, 31 insertions, 2 deletions
diff --git a/db/matcher.cpp b/db/matcher.cpp
index 78d9492a5be..dc50160f264 100644
--- a/db/matcher.cpp
+++ b/db/matcher.cpp
@@ -540,9 +540,16 @@ namespace mongo {
BSONObj temp = b.done();
JavaJS->scopeSetObject(where->scope, "obj", &temp);
}*/
- if ( JavaJS->invoke(where->scope, where->func) ) {
- uassert("error in invocation of $where function", false);
+ int err = JavaJS->invoke(where->scope, where->func);
+ if ( err == -3 ) { // INVOKE_ERROR
+ stringstream ss;
+ ss << "error on invocation of $where function:\n"
+ << JavaJS->scopeGetString(where->scope, "error");
+ uassert(ss.str(), false);
return false;
+ } else if ( err != 0 ) { // ! INVOKE_SUCCESS
+ uassert("error in invocation of $where function", false);
+ return false;
}
return JavaJS->scopeGetBoolean(where->scope, "return") != 0;
#else
diff --git a/jstests/error2.js b/jstests/error2.js
new file mode 100644
index 00000000000..5f2f5387424
--- /dev/null
+++ b/jstests/error2.js
@@ -0,0 +1,20 @@
+// Test that client gets stack trace on failed invoke
+
+f = db.jstests_error2;
+
+f.drop();
+
+f.save( {a:1} );
+
+c = f.find({$where : function(){ return a() }});
+try {
+ c.next();
+} catch( e ) {
+ assert( e.match( /java.lang.NullPointerException/ ) );
+}
+
+try {
+ db.eval( function() { return a(); } );
+} catch ( e ) {
+ assert( e.match( /java.lang.NullPointerException/ ) );
+}
diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj
index 5e59bbf4c32..45ef84ee355 100644
--- a/mongo.xcodeproj/project.pbxproj
+++ b/mongo.xcodeproj/project.pbxproj
@@ -122,6 +122,7 @@
934DD88B0EFAD23B00459CC1 /* sock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sock.h; sourceTree = "<group>"; };
934DD88D0EFAD23B00459CC1 /* unittest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unittest.h; sourceTree = "<group>"; };
934DD88E0EFAD23B00459CC1 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = util.cpp; sourceTree = "<group>"; };
+ 9350E1220F8CFFB300B07A1C /* error2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = error2.js; sourceTree = "<group>"; };
936AB4BB0F3A5B0300D5015F /* update3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = update3.js; sourceTree = "<group>"; };
936AB9350F3C8AB800D5015F /* _lodeRunner.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = _lodeRunner.js; sourceTree = "<group>"; };
936ABBAB0F3CBE5400D5015F /* dbNoCreate.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = dbNoCreate.js; sourceTree = "<group>"; };
@@ -542,6 +543,7 @@
93A8D1D10F37544800C92B85 /* jstests */ = {
isa = PBXGroup;
children = (
+ 9350E1220F8CFFB300B07A1C /* error2.js */,
93E55A260F8BE5320027A4A6 /* rename.js */,
93E559BF0F8BC6AC0027A4A6 /* drop.js */,
9339D4470F8B9D290063DBEF /* multi.js */,