Skip to content

Commit a404852

Browse files
committed
add AlreadyRanError class
1 parent 0d9d7c8 commit a404852

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const AlreadyRanError = require('./src/error/alreadyRan');
34
const { exec } = require('child_process');
45
const fs = require('fs');
56
const migrationSchema = require('./src/schemas/migrationSchema');
@@ -15,6 +16,8 @@ let didInit = false;
1516

1617
exports.models = { Migration: null, Operation: null };
1718

19+
exports.AlreadyRanError = AlreadyRanError;
20+
1821
const writeOps = [
1922
// Update
2023
'findOneAndReplace',
@@ -196,7 +199,7 @@ exports.startMigration = async function startMigration(options) {
196199

197200
const existingMigration = await Migration.exists({ name });
198201
if (existingMigration) {
199-
throw new Error(`Migration "${name}" already ran`);
202+
throw new AlreadyRanError(`Migration "${name}" already ran`);
200203
}
201204

202205
const sourceCode = await new Promise(resolve => {

src/error/alreadyRan.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
class AlreadyRanError extends Error {}
4+
5+
module.exports = AlreadyRanError;

0 commit comments

Comments
 (0)