diff --git a/package.json b/package.json index d8af9080..0f1df3e8 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "node": ">=6" }, "dependencies": { - "@babel/polyfill": "^7.0.0", + "@babel/polyfill": "^7.2.5", "@types/bluebird": "^3.5.25", "bluebird": "^3.5.3", "chalk": "2.4.1", @@ -24,7 +24,7 @@ "tarn": "^1.1.4", "tildify": "1.2.0", "uuid": "^3.3.2", - "v8flags": "^3.1.1" + "v8flags": "^3.1.2" }, "lint-staged": { "*.{js,json}": [ @@ -33,9 +33,9 @@ ] }, "devDependencies": { - "@babel/cli": "^7.2.0", + "@babel/cli": "^7.2.3", "@babel/core": "^7.2.2", - "@babel/preset-env": "^7.2.0", + "@babel/preset-env": "^7.2.3", "@types/node": "*", "JSONStream": "^1.3.5", "async": "^2.6.1", @@ -124,9 +124,9 @@ "web": "https://github.com/tgriesser" }, "browser": { - "./lib/migrate/index.js": "./lib/util/noop.js", + "./lib/migrate/Migrator.js": "./lib/util/noop.js", "./lib/bin/cli.js": "./lib/util/noop.js", - "./lib/seed/index.js": "./lib/util/noop.js", + "./lib/seed/Seeder.js": "./lib/util/noop.js", "mssql": false, "mssql/lib/base": false, "tedious": false, diff --git a/src/seed/index.js b/src/seed/Seeder.js similarity index 92% rename from src/seed/index.js rename to src/seed/Seeder.js index fb055f76..4875b2b7 100644 --- a/src/seed/index.js +++ b/src/seed/Seeder.js @@ -128,6 +128,20 @@ Seeder.prototype._waterfallBatch = function(seeds) { .then(() => seed.seed(knex, Promise)) .then(() => { log.push(name); + }) + .catch((originalError) => { + const error = new Error( + `Error while executing "${name}" seed: ${originalError.message}` + ); + error.original = originalError; + error.stack = + error.stack + .split('\n') + .slice(0, 2) + .join('\n') + + '\n' + + originalError.stack; + throw error; }); }); diff --git a/src/util/make-knex.js b/src/util/make-knex.js index 8ef3cc42..d52d982a 100644 --- a/src/util/make-knex.js +++ b/src/util/make-knex.js @@ -1,7 +1,7 @@ import { EventEmitter } from 'events'; import Migrator from '../migrate/Migrator'; -import Seeder from '../seed'; +import Seeder from '../seed/Seeder'; import FunctionHelper from '../functionhelper'; import QueryInterface from '../query/methods'; import { assign } from 'lodash'; diff --git a/test/jake-util/seeds-error-knexfile.js b/test/jake-util/seeds-error-knexfile.js new file mode 100644 index 00000000..667c6477 --- /dev/null +++ b/test/jake-util/seeds-error-knexfile.js @@ -0,0 +1,9 @@ +module.exports = { + client: 'sqlite3', + connection: { + filename: __dirname + '/../test.sqlite3', + }, + seeds: { + directory: __dirname + '/seeds-error', + }, +}; diff --git a/test/jake-util/seeds-error/seeds.js b/test/jake-util/seeds-error/seeds.js new file mode 100644 index 00000000..03893efa --- /dev/null +++ b/test/jake-util/seeds-error/seeds.js @@ -0,0 +1,3 @@ +exports.seed = (knex, Promise) => { + throw new Error('Boom'); +}; diff --git a/test/jake/Jakefile b/test/jake/Jakefile index ef3a2473..16b112cf 100644 --- a/test/jake/Jakefile +++ b/test/jake/Jakefile @@ -5,10 +5,12 @@ const knexfileTests = require('./jakelib/knexfile-test').taskList; const migrateTests = require('./jakelib/migrate-test').taskList; +const seedTests = require('./jakelib/seed-test').taskList; const tests = [ ...knexfileTests, ...migrateTests, + ...seedTests ]; task('default', tests, () => { diff --git a/test/jake/jakelib/seed-test.js b/test/jake/jakelib/seed-test.js new file mode 100644 index 00000000..499985e6 --- /dev/null +++ b/test/jake/jakelib/seed-test.js @@ -0,0 +1,29 @@ +#!/usr/bin/env jake +'use strict'; +/* eslint-disable no-undef */ + +const path = require('path'); +const { + assertExecError, + test, +} = require('../../jake-util/helpers/migration-test-helper'); +const { assert } = require('chai'); + +const KNEX = path.normalize(__dirname + '/../../../bin/cli.js'); + +const taskList = []; +/* * * TESTS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +test(taskList, 'Handles seeding errors correctly', (temp) => { + return assertExecError( + `node ${KNEX} seed:run --knexfile=test/jake-util/seeds-error-knexfile.js --knexpath=../knex.js` + ).then((err) => { + assert.include(err, 'Error while executing'); + assert.include(err, 'seeds.js'); + assert.include(err, 'Boom'); + }); +}); + +module.exports = { + taskList, +}; diff --git a/test/tape/seed.js b/test/tape/seed.js index 7b8ef8fb..39383c41 100644 --- a/test/tape/seed.js +++ b/test/tape/seed.js @@ -1,7 +1,7 @@ 'use strict'; const tape = require('tape'); -const Seed = require('../../lib/seed/index.js'); +const Seed = require('../../lib/seed/Seeder'); tape('checks config.seeds for seed config', function(t) { t.plan(1);