From 9dcf30efe966d73640618f4a7274df3f46d3a3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 26 Feb 2016 14:00:24 +0100 Subject: [PATCH] Improve error message on connector init error --- lib/datasource.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 2fa215e1..70484a6e 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -327,13 +327,22 @@ DataSource.prototype.setup = function (name, settings) { }.bind(this); - if ('function' === typeof connector.initialize) { - // Call the async initialize method - connector.initialize(this, postInit); - } else if ('function' === typeof connector) { - // Use the connector constructor directly - this.connector = new connector(this.settings); - postInit(); + try { + if ('function' === typeof connector.initialize) { + // Call the async initialize method + connector.initialize(this, postInit); + } else if ('function' === typeof connector) { + // Use the connector constructor directly + this.connector = new connector(this.settings); + postInit(); + } + } catch(err) { + if (err.message) { + err.message = 'Cannot initialize connector ' + + JSON.stringify(connector.name || name) + ': ' + + err.message; + } + throw err; } }