From aa34504aef0d85ec8b3f3a77ff9391160bb0d407 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Wed, 12 Jun 2013 08:43:02 -0400 Subject: [PATCH 1/2] ensure errors are thrown for fn's, fixes #16 --- knex.js | 9 ++++++++- test/lib/selects.js | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/knex.js b/knex.js index bdde6826..cb12bb1e 100644 --- a/knex.js +++ b/knex.js @@ -25,6 +25,10 @@ // Keep in sync with package.json Knex.VERSION = '0.1.6'; + var rethrower = function(err) { + throw err; + }; + // Methods common to both the `Grammar` and `SchemaGrammar` interfaces, // used to generate the sql in one form or another. var Common = { @@ -40,13 +44,16 @@ // For those who dislike promise interfaces. // Multiple calls to `exec` will resolve with the same value - // if called more than once. + // if called more than once. Any unhandled errors will be thrown + // after the last block. exec: function(callback) { this._promise || (this._promise = this.runQuery()); return this._promise.then(function(resp) { callback(null, resp); }, function(err) { callback(err, null); + }).then(null, function(err) { + setTimeout(function() { throw err; }, 0); }); }, diff --git a/test/lib/selects.js b/test/lib/selects.js index c9d3a515..6ec14c59 100644 --- a/test/lib/selects.js +++ b/test/lib/selects.js @@ -1,4 +1,6 @@ -var When = require('when'); +var When = require('when'); +var assert = require('assert'); + module.exports = function(Knex, dbName, resolver) { describe(dbName, function() { @@ -7,6 +9,25 @@ module.exports = function(Knex, dbName, resolver) { Knex('accounts').select().then(resolver(ok), ok); }); + it('throws errors on the exec if uncaught in the last block', function(ok) { + + var listeners = process.listeners('uncaughtException'); + + process.removeAllListeners('uncaughtException'); + + process.on('uncaughtException', function(err) { + process.removeAllListeners('uncaughtException'); + for (var i = 0, l = listeners.length; i < l; i++) { + process.on('uncaughtException', listeners[i]); + } + ok(); + }); + + Knex('accounts').select().exec(function(err, resp) { + console.log(undefinedVar); + }); + }); + it('uses `orderBy`', function(ok) { Knex('accounts') .select() From 38136e5cfcec3f3f2055442e9a84ae0217065ef7 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Wed, 12 Jun 2013 08:44:49 -0400 Subject: [PATCH 2/2] 0.1.7 --- docs/knex.html | 13 ++++++++++--- index.html | 9 +++++++-- knex.js | 4 ++-- package.json | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/knex.html b/docs/knex.html index 1c9317df..386a371d 100644 --- a/docs/knex.html +++ b/docs/knex.html @@ -27,7 +27,7 @@
-
Knex.js  0.1.6
+              
Knex.js  0.1.7
 
 (c) 2013 Tim Griesser
 Knex may be freely distributed under the MIT license.
@@ -91,7 +91,11 @@ http://knexjs.org
-
  Knex.VERSION = '0.1.6';
+
  Knex.VERSION = '0.1.7';
+
+  var rethrower = function(err) {
+    throw err;
+  };
@@ -129,7 +133,8 @@ used to generate the sql in one form or another.

For those who dislike promise interfaces. Multiple calls to exec will resolve with the same value -if called more than once.

+if called more than once. Any unhandled errors will be thrown +after the last block.

@@ -139,6 +144,8 @@ if called more than once.

callback(null, resp); }, function(err) { callback(err, null); + }).then(null, function(err) { + setTimeout(function() { throw err; }, 0); }); },
diff --git a/index.html b/index.html index 7c603da4..ace7c8bd 100644 --- a/index.html +++ b/index.html @@ -181,7 +181,7 @@