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

Commit 532754f6 by Mick Hansen

Better mysql error handling

1 parent a5b80a77
......@@ -38,8 +38,8 @@ module.exports = (function() {
var self = this
if (this.useReplicaton) {
var reads = 0,
writes = 0;
var reads = 0
, writes = 0;
// Init configs with options from config if not present
for (var i in config.replication.read) {
......@@ -122,7 +122,10 @@ module.exports = (function() {
this.pool = Pooling.Pool({
name: 'sequelize-mysql',
create: function (done) {
connect.call(self, done)
connect.call(self, function (err, connection) {
// This has to be nested for some reason, else the error won't propagate correctly
done(err, connection);
})
},
destroy: function(client) {
disconnect.call(self, client)
......@@ -148,8 +151,6 @@ module.exports = (function() {
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype);
var isConnecting = false;
ConnectorManager.prototype.query = function(sql, callee, options) {
if (!this.isConnected && !this.pool) {
this.connect()
......@@ -163,7 +164,7 @@ module.exports = (function() {
queueItem.query.options.uuid = this.config.uuid
enqueue.call(this, queueItem, options)
return queueItem.query
return queueItem.query;
}
var self = this, query = new Query(this.client, this.sequelize, callee, options || {});
......@@ -282,17 +283,30 @@ module.exports = (function() {
case 'EINVAL':
emitter.emit('error', 'Failed to find MySQL server. Please double check your settings.')
break
default:
emitter.emit('error', err);
break;
}
return;
}
emitter.emit('success', connection);
})
connection.query("SET time_zone = '+0:00'");
// client.setMaxListeners(self.maxConcurrentQueries)
this.isConnecting = false
if (config.pool != null && config.pool.handleDisconnects) {
if (config.pool !== null && config.pool.handleDisconnects) {
handleDisconnect(this.pool, connection)
}
done(null, connection)
emitter.on('error', function (err) {
done(err);
});
emitter.on('success', function (connection) {
done(null, connection);
});
}
var handleDisconnect = function(pool, client) {
......
......@@ -431,7 +431,7 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
})
it('fails with incorrect database connection details', function (done) {
it('fails with incorrect database credentials (3)', function (done) {
var sequelize = new Sequelize('db', 'user', 'pass', {
dialect: this.sequelize.options.dialect,
port: 99999
......@@ -445,6 +445,22 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
done()
})
})
it('fails with incorrect database credentials (4)', function (done) {
var sequelize = new Sequelize('db', 'user', 'pass', {
dialect: this.sequelize.options.dialect,
port: 99999,
pool: {}
});
var Project = sequelize.define('Project', {title: Sequelize.STRING})
var Task = sequelize.define('Task', {title: Sequelize.STRING})
sequelize.sync({force: true}).done(function (err) {
expect(err).to.be.ok
done()
})
})
}
describe("doesn't emit logging when explicitly saying not to", function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!