Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI Doesn't Halt On Error? #106

Closed
paulxtiseo opened this issue Mar 8, 2015 · 7 comments
Closed

CLI Doesn't Halt On Error? #106

paulxtiseo opened this issue Mar 8, 2015 · 7 comments

Comments

@paulxtiseo
Copy link

When I run sequelize db:migrate I see the error (and get the root SQL error), but the processing continues onwards to subsequent files instead of halting and allowing the user to fix the error. The first error because I did not know UNSIGNED in a createTable() didn't work against postgresql. The code was just a single createTable() with a done() afterwards. The other was an extra parens in a raw SQL statement that created a function using a migration.sequelize.query(<string>).nodeify(done) call.

In both cases, I did get the proper SequelizeDatabaseError with a message that described the error well, But, it proceeded on with subsequent file... and triggering more errors as dependent objects were not created properly.

Using Node 0.12.0, CLI 1.3.1 and ORM 2.0.3.

Example error:

Possibly unhandled SequelizeDatabaseError: syntax error at or near "UNSIGNED"
    at module.exports.Query.formatError (/Users/nnnn/Repositories/dddd/server-ah/node_modules/sequelize/lib/dialects/postgres/query.js:361:16)
    at null.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/sequelize/lib/dialects/postgres/query.js:79:21)
    at emit (events.js:107:17)
    at Query.handleError (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/query.js:99:8)
    at null.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/client.js:166:26)
    at emit (events.js:107:17)
    at Socket.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/connection.js:109:12)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:529:20)
@sdepold
Copy link
Member

sdepold commented Mar 8, 2015

Thanks for the report. Will check and fix soon.

On Sun, Mar 8, 2015 at 10:25 PM, Paul Tiseo notifications@github.com
wrote:

When I run sequelize db:migrate I see the error (and get the root SQL error), but the processing continues onwards to subsequent files instead of halting and allowing the user to fix the error. The first error because I did not know UNSIGNED in a createTable() didn't work against postgresql. The code was just a single createTable() with a done() afterwards. The other was an extra parens in a raw SQL statement that created a function using a migration.sequelize.query(<string>).nodeify(done) call.
In both cases, I did get the proper SequelizeDatabaseError with a message that described the error well, But, it proceeded on with subsequent file... and triggering more errors as dependent objects were not created properly.
Using Node 0.12.0, CLI 1.3.1 and ORM 2.0.3.
Example error:

Possibly unhandled SequelizeDatabaseError: syntax error at or near "UNSIGNED"
    at module.exports.Query.formatError (/Users/nnnn/Repositories/dddd/server-ah/node_modules/sequelize/lib/dialects/postgres/query.js:361:16)
    at null.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/sequelize/lib/dialects/postgres/query.js:79:21)
    at emit (events.js:107:17)
    at Query.handleError (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/query.js:99:8)
    at null.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/client.js:166:26)
    at emit (events.js:107:17)
    at Socket.<anonymous> (/Users/nnnn/Repositories/dddd/server-ah/node_modules/pg/lib/connection.js:109:12)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:529:20)

Reply to this email directly or view it on GitHub:
#106

@sdepold
Copy link
Member

sdepold commented Mar 14, 2015

Alright so here is what I tried:

I have the following migrations:

  • 0150213191225-create-user.js which creates a user table
  • 20150314204703-broken.js which queries a table that does not exist
  • 20150314204901-works.js which does not do anything but call the done callback

the broken migration looks like this:

"use strict";

module.exports = {
  up: function(queryInterface) {
    return queryInterface.sequelize.query('SELECT * FROM nomnomnom;');
  },

  down: function(migration, DataTypes, done) {
    // add reverting commands here, calling 'done' when finished
    done();
  }
};

Running the migrations results in the following output:

sequelize db:migrate

Sequelize [Node: 0.10.36, CLI: 1.4.0, ORM: 1.7.10]

Loaded configuration file 'config/config.json'.
Using environment 'development'.
== 20150213191225-create-user: migrating =======
== 20150213191225-create-user: migrated (0.010s)

== 20150314204703-broken: migrating =======
Possibly unhandled Error: SQLITE_ERROR: no such table: nomnomnom

The meta table contains only the first migration. Looks perfectly fine for me.

@sdepold
Copy link
Member

sdepold commented Mar 14, 2015

Can you paste the complete migration?

@jscti
Copy link

jscti commented Aug 19, 2015

Hello

I think the original problem is that sequelize doesn't throw any error in the console, it just output to stdout an error message.

I have a deployment .sh script running (in the middle of it) the command sequelize db:migrate, and if any error occurs (sequelize.json doesn't exists for example), the script isn't exited (and I don't see the error, as I chose to ignore standard output to only see errors)

test.sh :
node_modules/.bin/sequelize db:migrate
echo shouldnotbedisplayed

@biletskyidm
Copy link

biletskyidm commented Nov 15, 2016

I can reproduce this error.

That's my test migration

module.exports = {
  up: function(queryInterface, Sequelize) {
    queryInterface.changeColumn('Products', 'max_price', {
      type: Sequelize.INTEGER(11),
      references: {
        model: 'Users',
        key: 'id'
      }
    });
  },

  down: function(queryInterface) {
    queryInterface.sequelize.query('ALTER TABLE Products DROP FOREIGN KEY Productstest_max_price_foreign_idx;');
    queryInterface.removeIndex('Products', 'Productstest_max_price_foreign_idx');
  }
};

When I try to do sequelize db:migrate:undo, sequelize throws error in the console
Unhandled rejection SequelizeDatabaseError: Can't DROP 'Productstest_max_price_foreign_idx'; check that column/key exists

but migration was removed anyway
sql DELETE FROM SequelizeMetaWHEREname` = '20161115140347-test.js'``

@edin-m
Copy link

edin-m commented Dec 2, 2016

@BiletskiyDmitriy you need to return promise.
So return queryInterface.addColumn(... or if you have multiple stuff to do then you can return Promise.all([ queryInter..., queryInter... ]); or you can chain together multiple nested/related promises as promises are usually nested.

@sushantdhiman sushantdhiman mentioned this issue Sep 1, 2017
@sushantdhiman
Copy link
Contributor

480f3fc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants