From 164aea6826a351ae3aad2ecc8a2d55e8db1f8d51 Mon Sep 17 00:00:00 2001 From: Roman Fromrome Date: Mon, 29 Dec 2014 20:44:58 +0200 Subject: [PATCH 1/2] fixed thrown error check --- lib/ORM.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ORM.js b/lib/ORM.js index bf6a483a..bcbcfc71 100644 --- a/lib/ORM.js +++ b/lib/ORM.js @@ -134,7 +134,7 @@ exports.connect = function (opts, cb) { db.emit("connect", err, !err ? db : null); }); } catch (ex) { - if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module')) { + if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module') > -1) { return ORM_Error(new ORMError("Connection protocol not supported - have you installed the database driver for " + proto + "?", 'NO_SUPPORT'), cb); } return ORM_Error(ex, cb); From fbb53fa9185e0a1ea07c591a3e4c264eaccc93bf Mon Sep 17 00:00:00 2001 From: Roman Fromrome Date: Tue, 13 Jan 2015 21:46:26 +0200 Subject: [PATCH 2/2] added test for valid error throwing in connection try block --- test/integration/orm-exports.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/orm-exports.js b/test/integration/orm-exports.js index 0f20ec08..3b9f1665 100644 --- a/test/integration/orm-exports.js +++ b/test/integration/orm-exports.js @@ -139,6 +139,26 @@ describe("ORM.connect()", function () { }); }); + it("should emit valid error if exception being thrown during connection try", function (done) { + var testConfig = { + protocol : 'mongodb', + href : 'unknownhost', + database : 'unknowndb', + user : '', + password : '' + }, + db = ORM.connect(testConfig); + + db.on("connect", function (err) { + should.exist(err); + should.equal(err.message.indexOf("Connection protocol not supported"), -1); + err.message.should.not.equal("CONNECTION_URL_NO_PROTOCOL"); + err.message.should.not.equal("CONNECTION_URL_EMPTY"); + + return done(); + }); + }); + it("should not modify connection opts", function (done) { var opts = { protocol : 'mysql',