Display name of a failed seed (#2973)

This commit is contained in:
Igor Savin 2018-12-27 18:20:13 +01:00 committed by GitHub
parent 0b26935273
commit 9daf7f3d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 8 deletions

View File

@ -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,

View File

@ -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;
});
});

View File

@ -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';

View File

@ -0,0 +1,9 @@
module.exports = {
client: 'sqlite3',
connection: {
filename: __dirname + '/../test.sqlite3',
},
seeds: {
directory: __dirname + '/seeds-error',
},
};

View File

@ -0,0 +1,3 @@
exports.seed = (knex, Promise) => {
throw new Error('Boom');
};

View File

@ -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, () => {

View File

@ -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,
};

View File

@ -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);