Log errors (instead of crashing) when the config file cannot be parsed

Also, config won't overwrite changes to config.cson when the file can not be parsed. Closes #401
This commit is contained in:
Corey Johnson
2013-03-12 16:47:26 -07:00
parent f7f034ad2a
commit c236325c1a
2 changed files with 28 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ class Config
userPackagesDirPath: userPackagesDirPath
defaultSettings: null
settings: null
configFileHasErrors: null
constructor: ->
@defaultSettings =
@@ -55,8 +56,13 @@ class Config
loadUserConfig: ->
if fs.exists(@configFilePath)
userConfig = fs.readObject(@configFilePath)
_.extend(@settings, userConfig)
try
userConfig = fs.readObject(@configFilePath)
_.extend(@settings, userConfig)
catch e
@configFileHasErrors = true
console.error "Failed to load user config '#{@configFilePath}'", e.message
console.error e.stack
get: (keyPath) ->
_.valueForKeyPath(@settings, keyPath) ?
@@ -92,6 +98,7 @@ class Config
subscription
update: ->
return if @configFileHasErrors
@save()
@trigger 'updated'