Skip to content

Commit c241092

Browse files
author
mikob
committed
Added try/catch around loading the sql and js migrations. Currently, node (<= 0.12) does not throw unhandled exceptions in promises... the newer node 0.13 should handle it. nodejs/node-v0.x-archive#8997
1 parent 966dc8b commit c241092

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/migrator.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,24 @@ function getExistingMigrations(migrationsDir) {
7979
for (let li = 0; li < list.length; li++) {
8080
if (m = list[li].match(/(.*)\.sql/)) {
8181
// if the file has a .sql extension, load it as a file read for sql schema updating
82-
migrations.push({
83-
id: m[1],
84-
sql: fs.readFileSync(migrationsDir + m[0]).toString()
85-
});
82+
try {
83+
migrations.push({
84+
id: m[1],
85+
sql: fs.readFileSync(migrationsDir + m[0]).toString()
86+
});
87+
} catch (err) {
88+
console.error(util.format("Error reading sql migration %s. \n%s", m[0], err));
89+
}
8690
} else if (j = list[li].match(/(.*)\.js/)) {
8791
// if the file has a .js extension, load via require system and set js attribute as .migrate function
88-
migrations.push({
89-
id: j[1],
90-
js: require(migrationsDir + "/" + list[li]).migrate
91-
});
92+
try {
93+
migrations.push({
94+
id: j[1],
95+
js: require(migrationsDir + "/" + list[li]).migrate
96+
});
97+
} catch (err) {
98+
console.error(util.format("Error reading js migration %s. \n%s", list[li], err));
99+
}
92100
}
93101
}
94102

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "migrator",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Take your datas and migrate them",
55
"author": {
66
"name": "Chris Williams",

0 commit comments

Comments
 (0)