From d758441cf4b7a9fcdf63a652d10364d6748c0120 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 15 Apr 2015 17:42:14 +1000 Subject: [PATCH] Added `throwStubExceptions` option to Meteor.call Allows method simulations to be used as validators and enables freely throwing exceptions in method definitions without worrying about spurious logging on the client. --- packages/ddp-client/livedata_connection.js | 13 +++++++++---- packages/ddp-client/livedata_tests.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/ddp-client/livedata_connection.js b/packages/ddp-client/livedata_connection.js index b59e486608..c3783fbfd0 100644 --- a/packages/ddp-client/livedata_connection.js +++ b/packages/ddp-client/livedata_connection.js @@ -823,13 +823,18 @@ _.extend(Connection.prototype, { // If an exception occurred in a stub, and we're ignoring it // because we're doing an RPC and want to use what the server - // returns instead, log it so the developer knows. + // returns instead, log it so the developer knows + // (unless they explicitly ask to see the error). // // Tests can set the 'expected' flag on an exception so it won't // go to log. - if (exception && !exception.expected) { - Meteor._debug("Exception while simulating the effect of invoking '" + - name + "'", exception, exception.stack); + if (exception) { + if (options.throwStubExceptions) { + throw exception; + } else if (!exception.expected) { + Meteor._debug("Exception while simulating the effect of invoking '" + + name + "'", exception, exception.stack); + } } diff --git a/packages/ddp-client/livedata_tests.js b/packages/ddp-client/livedata_tests.js index 2cf1373875..8b3e72d284 100644 --- a/packages/ddp-client/livedata_tests.js +++ b/packages/ddp-client/livedata_tests.js @@ -193,6 +193,19 @@ testAsyncMulti("livedata - basic method invocation", [ test.equal(Meteor.call("exception", "both"), undefined); test.equal(Meteor.call("exception", "server"), undefined); test.equal(Meteor.call("exception", "client"), undefined); + + // If we pass throwStubExceptions then we *should* see thrown exceptions + // on the client + test.throws(function () { + Meteor.apply("exception", ["both"], {throwStubExceptions: true}); + }); + test.equal( + Meteor.apply("exception", ["server"], {throwStubExceptions: true}), + undefined); + test.throws(function () { + Meteor.apply("exception", ["client"], {throwStubExceptions: true}); + }); + } // With callback