不要怂,就是干,撸起袖子干!

Commit 981e63ae by David Pate

Wrap errors from SQLLite in the new connection error objects. Update the Connect…

…ionError constructor so that it can handle a falsey error object being sent as a parameter. Update the configuration tests to support SQLite and it's custom messages as well as the lack of authentication.
1 parent 28ebbb78
......@@ -2,7 +2,8 @@
var AbstractConnectionManager = require('../abstract/connection-manager')
, ConnectionManager
, Utils = require('../../utils')
, Promise = require('../../promise');
, Promise = require('../../promise')
, sequelizeErrors = require('../../errors');
ConnectionManager = function(dialect, sequelize) {
this.sequelize = sequelize;
......@@ -29,8 +30,9 @@ ConnectionManager.prototype.getConnection = function(options) {
return new Promise(function (resolve, reject) {
self.connections[options.uuid] = new self.lib.Database(self.sequelize.options.storage || ':memory:', function(err) {
if (err) {
if (err.code === 'SQLITE_CANTOPEN') return reject('Failed to find SQL server. Please double check your settings.');
return reject(err);
console.log(err);
if (err.code === 'SQLITE_CANTOPEN') return reject(new sequelizeErrors.ConnectionError(err));
return reject(new sequelizeErrors.ConnectionError(err));
}
resolve(self.connections[options.uuid]);
});
......
......@@ -191,7 +191,7 @@ error.ValidationErrorItem = function(message, type, path, value) {
* @constructor
*/
error.ConnectionError = function (parent) {
error.BaseError.apply(this, [parent.message]);
error.BaseError.apply(this, [parent ? parent.message : '']);
this.name = 'SequelizeConnectionError';
this.parent = parent;
......
......@@ -11,12 +11,22 @@ describe(Support.getTestDialectTeaser("Configuration"), function() {
describe('Connections problems should fail with a nice message', function() {
it("when we don't have the correct server details", function(done) {
var seq = new Sequelize(config[dialect].database, config[dialect].username, config[dialect].password, {storage: '/path/to/no/where/land', logging: false, host: '0.0.0.1', port: config[dialect].port, dialect: dialect})
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.InvalidConnectionError, 'connect EINVAL')
if (dialect === 'sqlite') {
// SQLite doesn't have a breakdown of error codes, so we are unable to discern between the different types of errors.
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.ConnectionError, 'SQLITE_CANTOPEN: unable to open database file').notify(done)
} else {
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.InvalidConnectionError, 'connect EINVAL').notify(done)
}
})
it('when we don\'t have the correct login information', function(done) {
var seq = new Sequelize(config[dialect].database, config[dialect].username, 'fakepass123', {logging: false, host: config[dialect].host, port: 1, dialect: dialect})
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.ConnectionRefusedError, 'connect ECONNREFUSED')
if (dialect === 'sqlite') {
// SQLite doesn't require authentication and `select 1 as hello` is a valid query, so this should be fulfilled not rejected for it.
return expect(seq.query('select 1 as hello')).to.eventually.be.fulfilled.notify(done)
} else {
return expect(seq.query('select 1 as hello')).to.eventually.be.rejectedWith(seq.ConnectionRefusedError, 'connect ECONNREFUSED').notify(done)
}
})
it('when we don\'t have a valid dialect.', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!