summaryrefslogtreecommitdiff
path: root/jstests/core/mr_tolerates_js_exception.js
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2018-09-18 21:10:36 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2018-09-18 21:10:36 -0400
commitf43ea7a6bb2a6c44f91506c32004241d3cbb24ae (patch)
tree1dff1f481a3439045f0de84a242e1ac33f201249 /jstests/core/mr_tolerates_js_exception.js
parent78112be586c67efa877636d596b194650e90cbed (diff)
downloadmongo-f43ea7a6bb2a6c44f91506c32004241d3cbb24ae.tar.gz
SERVER-35154 Propagate JS exceptions through ScopedThread#join().
This makes it so that if the ScopedThread exited due to an uncaught JavaScript exception, then calling .join() or .returnData() on it throws a JavaScript exception with the error message and stacktrace intact.
Diffstat (limited to 'jstests/core/mr_tolerates_js_exception.js')
-rw-r--r--jstests/core/mr_tolerates_js_exception.js38
1 files changed, 33 insertions, 5 deletions
diff --git a/jstests/core/mr_tolerates_js_exception.js b/jstests/core/mr_tolerates_js_exception.js
index 47536a3cc3f..20e96eb47dc 100644
--- a/jstests/core/mr_tolerates_js_exception.js
+++ b/jstests/core/mr_tolerates_js_exception.js
@@ -1,7 +1,11 @@
-// @tags: [does_not_support_stepdowns]
-
/**
- * Test that the mapReduce command fails gracefully when user-provided JavaScript code throws.
+ * Test that the mapReduce command fails gracefully when user-provided JavaScript code throws and
+ * that the user gets back a JavaScript stacktrace.
+ *
+ * @tags: [
+ * does_not_support_stepdowns,
+ * requires_scripting,
+ * ]
*/
(function() {
"use strict";
@@ -20,18 +24,32 @@
emit(this.a, 1);
},
reduce: function(key, value) {
- throw 42;
+ (function myFunction() {
+ throw new Error("Intentionally thrown inside reduce function");
+ })();
},
out: {inline: 1}
});
assert.commandFailedWithCode(cmdOutput, ErrorCodes.JSInterpreterFailure, tojson(cmdOutput));
+ assert(/Intentionally thrown inside reduce function/.test(cmdOutput.errmsg),
+ () => "mapReduce didn't include the message from the exception thrown: " +
+ tojson(cmdOutput));
+ assert(/myFunction@/.test(cmdOutput.errmsg),
+ () => "mapReduce didn't return the JavaScript stacktrace: " + tojson(cmdOutput));
+ assert(
+ !cmdOutput.hasOwnProperty("stack"),
+ () => "mapReduce shouldn't return JavaScript stacktrace separately: " + tojson(cmdOutput));
+ assert(!cmdOutput.hasOwnProperty("originalError"),
+ () => "mapReduce shouldn't return wrapped version of the error: " + tojson(cmdOutput));
// Test that the command fails with a JS interpreter failure error when the map function
// throws.
cmdOutput = db.runCommand({
mapReduce: coll.getName(),
map: function() {
- throw 42;
+ (function myFunction() {
+ throw new Error("Intentionally thrown inside map function");
+ })();
},
reduce: function(key, value) {
return Array.sum(value);
@@ -39,4 +57,14 @@
out: {inline: 1}
});
assert.commandFailedWithCode(cmdOutput, ErrorCodes.JSInterpreterFailure, tojson(cmdOutput));
+ assert(/Intentionally thrown inside map function/.test(cmdOutput.errmsg),
+ () => "mapReduce didn't include the message from the exception thrown: " +
+ tojson(cmdOutput));
+ assert(/myFunction@/.test(cmdOutput.errmsg),
+ () => "mapReduce didn't return the JavaScript stacktrace: " + tojson(cmdOutput));
+ assert(
+ !cmdOutput.hasOwnProperty("stack"),
+ () => "mapReduce shouldn't return JavaScript stacktrace separately: " + tojson(cmdOutput));
+ assert(!cmdOutput.hasOwnProperty("originalError"),
+ () => "mapReduce shouldn't return wrapped version of the error: " + tojson(cmdOutput));
}());