不要怂,就是干,撸起袖子干!

Commit 4c23c8a1 by terraflubb

Throw nicer errors when we can't read config.json

And quit with a code after outputting it.
1 parent 6f65e6de
Showing with 19 additions and 6 deletions
......@@ -51,17 +51,23 @@ var createMigrationsFolder = function(force) {
}
var readConfig = function() {
var config
try {
var config = JSON.parse(fs.readFileSync(configFile))
config = fs.readFileSync(configFile)
} catch(e) {
throw new Error('Error reading "config/config.json".')
}
try {
config = JSON.parse(config)
} catch (e) {
throw new Error('Error parsing "config/config.json" as JSON.')
}
if (config[environment]) {
config = config[environment]
}
return config
} catch(e) {
throw new Error('The config.json is not available or contains invalid JSON.')
}
}
program
......@@ -81,9 +87,16 @@ console.log("Using environment '" + environment + "'.")
if(program.migrate) {
if(configFileExists) {
var config = readConfig()
var config
, options = {}
try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}
_.each(config, function(value, key) {
if(['database', 'username', 'password'].indexOf(key) == -1) {
options[key] = value
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!