fix(config): Report JSON parsing errors in a dialog #2102

This commit is contained in:
Ben Gotow 2016-05-04 12:05:04 -07:00
parent 54427ccb9d
commit 7834fe8b26

View file

@ -11,8 +11,10 @@ Color = require './color'
if global.application if global.application
app = global.application app = global.application
dialog = require('electron').dialog
else else
app = remote.getGlobal('application') app = remote.getGlobal('application')
dialog = remote.dialog
# Essential: Used to access all of N1's configuration details. # Essential: Used to access all of N1's configuration details.
# #
@ -561,12 +563,13 @@ class Config
@configFileHasErrors = true @configFileHasErrors = true
message = "Failed to load `#{path.basename(@configFilePath)}`" message = "Failed to load `#{path.basename(@configFilePath)}`"
detail = if error.location? if error.location?
# stack is the output from JSON in this case # stack is the output from JSON in this case
error.stack detail = error.stack
else else
# message will be EACCES permission denied, et al # message will be EACCES permission denied, et al
error.message detail = error.message
detail += "\n\nMake sure the file (#{@configFilePath}) contains valid JSON, or delete it to reset N1."
@notifyFailure(message, detail) @notifyFailure(message, detail)
@ -575,7 +578,7 @@ class Config
@watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) => @watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) =>
@requestLoad() if eventType is 'change' and @watchSubscription? @requestLoad() if eventType is 'change' and @watchSubscription?
catch error catch error
@notifyFailure """ @notifyFailure "Configuration Error", """
Unable to watch path: `#{path.basename(@configFilePath)}`. Make sure you have permissions to Unable to watch path: `#{path.basename(@configFilePath)}`. Make sure you have permissions to
`#{@configFilePath}`. On linux there are currently problems with watch `#{@configFilePath}`. On linux there are currently problems with watch
sizes. sizes.
@ -586,7 +589,7 @@ class Config
@watchSubscription = null @watchSubscription = null
notifyFailure: (errorMessage, detail) -> notifyFailure: (errorMessage, detail) ->
console.log(errorMessage, detail) dialog.showErrorBox(errorMessage, detail)
save: -> save: ->
manager = app.sharedFileManager manager = app.sharedFileManager