Permalink
Browse files

better error handling for broken database.json files

  • Loading branch information...
1 parent 79e96d0 commit e3ef1f156cebc60863b91d82b1999d6f3fbad53f @acruikshank acruikshank committed Feb 6, 2014
Showing with 24 additions and 0 deletions.
  1. +4 −0 lib/config.js
  2. +19 −0 test/config_test.js
  3. +1 −0 test/database.notjson
View
@@ -14,6 +14,10 @@ exports.load = function(fileName, currentEnv) {
try {
config = require(fileName);
} catch(e) {
+ // distinguish broken files from missing ones
+ if (e instanceof SyntaxError)
+ throw e;
+
config = require(path.join(process.cwd(), fileName));
}
View
@@ -37,6 +37,25 @@ vows.describe('config').addBatch({
assert.equal(current.settings.driver, 'sqlite3');
assert.equal(current.settings.filename, ':memory:');
}
+ },
+}).addBatch({
+ 'loading from a broken config file': {
+ topic: function() {
+ var configPath = path.join(__dirname, 'database.notjson');
+ config.load = _configLoad;
+ config.loadUrl = _configLoadUrl;
+ try {
+ config.load(configPath, 'dev');
+ } catch (e) {
+ return e;
+ }
+ return;
+ },
+
+ 'should throw a syntax error': function (error) {
+ assert.isDefined(error);
+ assert.ok(error instanceof SyntaxError, "Expected broken file to produce syntax error");
+ }
}
}).addBatch({
'loading from a file with ENV vars': {
View
@@ -0,0 +1 @@
+{this:'is' not:'valid' json}

0 comments on commit e3ef1f1

Please sign in to comment.