Skip to content

Warning: a promise was created in a handler but was not returned from it #545

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

Closed
1 of 2 tasks
jessev123 opened this issue Feb 8, 2018 · 6 comments
Closed
1 of 2 tasks

Comments

@jessev123
Copy link

jessev123 commented Feb 8, 2018

I'm submitting a...

  • Bug report
  • Feature request

Current behavior

When running any migration (up or down) the following error presents itself:

Warning: a promise was created in a handler but was not returned from it
    at Function.Migration.registerHook (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/lib/migration.js:41:20)
    at module.exports (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/lib/commands/helper/migration-hook.js:4:20)
    at module.exports (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/lib/commands/up.js:7:3)
    at run (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/lib/commands/run.js:64:9)
    at Object.run (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/api.js:439:16)
    at /Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/bin/db-migrate:36:19
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)
From previous event:
    at /Users/jessevanderwerf/taskspace/cloud-service/node_modules/db-migrate/bin/db-migrate:35:8
    at /Users/jessevanderwerf/taskspace/cloud-service/node_modules/resolve/lib/async.js:45:21
    at ondir (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/resolve/lib/async.js:196:27)
    at onex (/Users/jessevanderwerf/taskspace/cloud-service/node_modules/resolve/lib/async.js:104:32)
    at /Users/jessevanderwerf/taskspace/cloud-service/node_modules/resolve/lib/async.js:24:24
    at FSReqWrap.oncomplete (fs.js:123:15)

Expected behavior

Migrations should return all promises and not warn on extra promises not returning.

Minimal reproduction of the problem with instructions

we have a psql db. we are currently running the following versions:
db-migrate: 0.10.0
db-migrate-pg: 0.2.5
I have tried the latest published versions and still get the same error.
install the latest version of db-migrate and db-migrate-pg and run a migration.
I am attempting to run db-migrate up with no migrations (just to see if the warning goes away without our migrations)
As a side note our migrations are all of the callback variety. It is happening for our whole team.

What is the motivation / use case for changing the behavior?

I would think that if db-migrate is leaving promises un-resolved they would like to know about it verify where (if it is in your codebase) and resolve them and if not then perhaps pin bluebird and notify them of the warnings.

Or

If its something in how we are currently using db-migrate we'd like to modify how we are doing things to remove the warning.

Environment


db-migrate version: 0.10.0
plugins with versions: 0.2.5
db-migrate driver with versions: 
db-migrate-pg v0.2.5 
Additional information:
- Node version: 6.5.0  
- Platform: Mac 

Others:

@wzrdtales
Copy link
Member

This is most probably an user error and not releated to db-migrate. See https://github.com/petkaantonov/bluebird/blob/master/docs/docs/warning-explanations.md#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it

To help you identify what exactly you're doing wrong you would need to show us the migration that you've written that is failing here.

@wzrdtales
Copy link
Member

Best provide a gist or example project, to help on this topic.

@jessev123
Copy link
Author

jessev123 commented Feb 8, 2018

Sure. Thanks for the quick response. Basically we have a number of one off migrations and a few async series (if I were a betting man I'd bet the series could use some work) It is also interesting to note that even removing all migrations but 1 simple migration still results in the warning.

Please take a look at my at the examples below. Let me know if there is anything more I can provide you.
Simple migration example:

var dbm = global.dbm || require('db-migrate');
var type = dbm.dataType;

exports.up = function(db, callback) {
  db.createTable('_emails', {
    id: { &1},
    user_id: {
      type: 'string',
      length:n
    },
    email: { &stuff }
    }, callback);
};

exports.down = function(db, callback) {
  db.dropTable('_emails', callback);
};

async.series example

exports.up = function(db, callback) {
  async.series([
    db.addForeignKey.bind(db, NAME, 'users', USERS_KEY,
      {
        '_id': 'id'
      },
      {
        onDelete: 'CASCADE',
        onUpdate: 'RESTRICT'
      }),
    db.addForeignKey.bind(db, NAME, 'user_agreements', AGREEMENTS,
      {
        'agreement_id': 'id'
      },
      {
        onDelete: 'CASCADE',
        onUpdate: 'RESTRICT'
      })
  ], callback);
}

exports.down = function(db, callback) {
  async.series([
    db.removeForeignKey.bind(db, NAME, USERS_KEY),
    db.removeForeignKey.bind(db, NAME, AGREEMENTS)
  ], callback);
};

thanks for your help.

@wzrdtales
Copy link
Member

wzrdtales commented Feb 8, 2018

Actually impossible to reproducce, even with your examples, I do not run into any trouble executing either of those.

However this style is really really old though.

The second one would look like this today

exports.up = async function (db) {
  await db.addForeignKey(
    NAME,
    'users',
    USERS_KEY,
    {
      _id: 'id'
    },
    {
      onDelete: 'CASCADE',
      onUpdate: 'RESTRICT'
    }
  );
  return db.addForeignKey(
    NAME,
    'user_agreements',
    AGREEMENTS,
    {
      agreement_id: 'id'
    },
    {
      onDelete: 'CASCADE',
      onUpdate: 'RESTRICT'
    }
  );
};

exports.down = async function (db) {
  await db.removeForeignKey(NAME, USERS_KEY);
  return db.removeForeignKey(NAME, AGREEMENTS);
};

As you're still on node 6 and don't have natively async/await you can fall back to:

exports.up = function (db) {
  return db
    .addForeignKey(
      NAME,
      'users',
      USERS_KEY,
      {
        _id: 'id'
      },
      {
        onDelete: 'CASCADE',
        onUpdate: 'RESTRICT'
      }
    )
    .then(() =>
      db.addForeignKey(
        NAME,
        'user_agreements',
        AGREEMENTS,
        {
          agreement_id: 'id'
        },
        {
          onDelete: 'CASCADE',
          onUpdate: 'RESTRICT'
        }
      )
    );
};

exports.down = function (db) {
  return db
    .removeForeignKey(NAME, USERS_KEY)
    .then(() => db.removeForeignKey(NAME, AGREEMENTS));
};

@wzrdtales
Copy link
Member

wzrdtales commented Feb 8, 2018

Also take a look at what the create command creates for you. The global.dbm was long since removed and is not needed anymore at all. There is a setup method now.

@stale
Copy link

stale bot commented Mar 10, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

2 participants