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

Rethrow execution error with errInfo #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/actions/up.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
const _ = require("lodash");
const pEachSeries = require("p-each-series");
const { promisify } = require("util");
const fnArgs = require('fn-args');
const fnArgs = require("fn-args");

const status = require("./status");
const config = require("../env/config");
const migrationsDir = require("../env/migrationsDir");
const hasCallback = require('../utils/has-callback');
const hasCallback = require("../utils/has-callback");

module.exports = async (db, client) => {
const statusItems = await status(db);
const pendingItems = _.filter(statusItems, { appliedAt: "PENDING" });
const migrated = [];

const migrateItem = async item => {
const migrateItem = async (item) => {
try {
const migration = await migrationsDir.loadMigration(item.fileName);
const up = hasCallback(migration.up) ? promisify(migration.up) : migration.up;
const up = hasCallback(migration.up)
? promisify(migration.up)
: migration.up;

if (hasCallback(migration.up) && fnArgs(migration.up).length < 3) {
// support old callback-based migrations prior to migrate-mongo 7.x.x
await up(db);
} else {
await up(db, client);
}

} catch (err) {
const error = new Error(
`Could not migrate up ${item.fileName}: ${err.message}`
`Could not migrate up ${item.fileName}: ${err.message}`,
);
error.stack = err.stack;
error.migrated = migrated;
error.additionalInfo = err.errInfo;
throw error;
}

Expand All @@ -41,7 +43,11 @@ module.exports = async (db, client) => {
const appliedAt = new Date();

try {
await changelogCollection.insertOne(useFileHash === true ? { fileName, fileHash, appliedAt } : { fileName, appliedAt });
await changelogCollection.insertOne(
useFileHash === true
? { fileName, fileHash, appliedAt }
: { fileName, appliedAt },
);
} catch (err) {
throw new Error(`Could not update changelog: ${err.message}`);
}
Expand Down