sequelize: MySQL Connection Error Handling

Hello,

I’ve run into a potential issue and I’m not 100% sure if it’s a bug with the mysql connection manager or something I’m doing.

When triggering a connection failure on sequelize.sync() the error events do not seem to propagate up out of the connection-manager.js I’ve attached an event listener using the .error() method on the sequelize.sync() which works perfectly with sqlite. But when using mysql the callback is never triggered.

var Sequelize = require("sequelize");
var sequelize = new Sequelize(database, user, pass, _opts);

// Defined Models

sequelize.sync().success(function() {
    console.log("Models Synced");
}).error(function(err) {
    console.log("Error: OOOH NOOOES");
});

The above will generate the following error

TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at EventEmitter.emit (events.js:74:15)
    at Handshake._callback (./node_modules/sequelize/lib/dialects/mysql/connector-manager.js:278:19)
    at Handshake.Sequence.end (./node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
    at Protocol.handleNetworkError (./node_modules/mysql/lib/protocol/Protocol.js:238:14)
    at Connection._handleNetworkError (./node_modules/mysql/lib/Connection.js:155:18)
    at Socket.EventEmitter.emit (events.js:117:20)
    at net.js:830:16
    at process._tickCallback (node.js:415:13)
22 Oct 23:49:29 - [nodemon] app crashed - waiting for file changes before starting...

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

const { Sequelize } = require('sequelize');

const sequelize = new Sequelize('database', 'name', 'password', {
    host: '127.0.0.1',  // or host: 'localhost'
    dialect: 'mysql',
    port: 5043, // your port 
    dialectOptions: { // optional if you have xampp or port borken
        socketPath: "/opt/lampp/var/mysql/mysql.sock"
    },
})