Skip to content

Commit f6e8e39

Browse files
committed
Merge pull request #149 from acruikshank/master
better error handling for broken database.json files
2 parents 79e96d0 + 8e61008 commit f6e8e39

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ exports.load = function(fileName, currentEnv) {
1414
try {
1515
config = require(fileName);
1616
} catch(e) {
17+
// distinguish broken files from missing ones
18+
if (e instanceof SyntaxError){
19+
throw e;
20+
}
21+
1722
config = require(path.join(process.cwd(), fileName));
1823
}
1924

test/config_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ vows.describe('config').addBatch({
3737
assert.equal(current.settings.driver, 'sqlite3');
3838
assert.equal(current.settings.filename, ':memory:');
3939
}
40+
},
41+
}).addBatch({
42+
'loading from a broken config file': {
43+
topic: function() {
44+
var configPath = path.join(__dirname, 'database.notjson');
45+
config.load = _configLoad;
46+
config.loadUrl = _configLoadUrl;
47+
try {
48+
config.load(configPath, 'dev');
49+
} catch (e) {
50+
return e;
51+
}
52+
return;
53+
},
54+
55+
'should throw a syntax error': function (error) {
56+
assert.isDefined(error);
57+
assert.ok(error instanceof SyntaxError, "Expected broken file to produce syntax error");
58+
}
4059
}
4160
}).addBatch({
4261
'loading from a file with ENV vars': {

test/database.notjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{this:'is' not:'valid' json}

0 commit comments

Comments
 (0)