Files
mongo/jstests/core/where_tolerates_js_exception.js
Max Hirschhorn f43ea7a6bb 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.
2018-09-18 21:10:36 -04:00

36 lines
1.1 KiB
JavaScript

/**
* Test that $where fails gracefully when user-provided JavaScript code throws and that the user
* gets back the JavaScript stacktrace.
*
* @tags: [
* requires_non_retryable_commands,
* requires_scripting,
* ]
*/
(function() {
"use strict";
const collection = db.where_tolerates_js_exception;
collection.drop();
assert.commandWorked(collection.save({a: 1}));
const res = collection.runCommand("find", {
filter: {
$where: function myFunction() {
return a();
}
}
});
assert.commandFailedWithCode(res, ErrorCodes.JSInterpreterFailure);
assert(/ReferenceError/.test(res.errmsg),
() => "$where didn't failed with a ReferenceError: " + tojson(res));
assert(/myFunction@/.test(res.errmsg),
() => "$where didn't return the JavaScript stacktrace: " + tojson(res));
assert(!res.hasOwnProperty("stack"),
() => "$where shouldn't return JavaScript stacktrace separately: " + tojson(res));
assert(!res.hasOwnProperty("originalError"),
() => "$where shouldn't return wrapped version of the error: " + tojson(res));
})();