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

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