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

Error requiring migration file obfuscated by library's error handling #33

Closed
willshowell opened this issue Oct 18, 2018 · 1 comment
Closed

Comments

@willshowell
Copy link

Describe the bug

The error handler for up tries to log the migrations that couldn't be run. This is done in /bin/migrate-mongo on L72.

program
.command("up")
.description("run all pending database migrations")
.option("-f --file <file>", "use a custom config file")
.action(options => {
global.options = options;
migrateMongo.database
.connect()
.then(db => migrateMongo.up(db))
.then(migrated => {
printMigrated(migrated);
process.exit(0);
})
.catch(err => {
printMigrated(err.migrated);
handleError(err);
});
});

But if err.migrated is undefined, then a new error is thrown before the original error can be logged:

TypeError: Cannot read property 'forEach' of undefined
    at printMigrated (node_modules/migrate-mongo/bin/migrate-mongo.js:12:12)
    at database.connect.then.then.catch.err (node_modules/migrate-mongo/bin/migrate-mongo.js:74:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Unfortunately, some errors are thrown that don't have the migrated property, so it's difficult to get visibility into them.

To Reproduce

  • write a migration that throws an error when required
    // requiring this file will error due to using await inside non-async fn
    module.exports = {
      up(db) {
        await somePromise
      }
    
      down(db) { }
    };
  • use migrate-mongo up

Other

Also if inserting the migration to the db collection fails, then you'll get an invalid error there as well:

try {
await collection.insertOne({ fileName, appliedAt });
} catch (err) {
throw new Error(`Could not update changelog: ${err.message}`);
}

@seppevs
Copy link
Owner

seppevs commented Oct 22, 2018

Should be resolved in v4.1.2
See #34

@seppevs seppevs closed this as completed Oct 22, 2018
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

2 participants