Use atom.notifications when there is a config file error

This commit is contained in:
Ben Ogle
2014-11-24 15:52:22 -08:00
parent 4cb80d3c7e
commit 362bd2e61a
2 changed files with 11 additions and 5 deletions

View File

@@ -554,11 +554,13 @@ describe "Config", ->
describe "when the config file contains invalid cson", ->
beforeEach ->
spyOn(console, 'error')
spyOn(atom.notifications, 'addError')
fs.writeFileSync(atom.config.configFilePath, "{{{{{")
it "logs an error to the console and does not overwrite the config file on a subsequent save", ->
atom.config.loadUserConfig()
expect(console.error).toHaveBeenCalled()
expect(atom.notifications.addError.callCount).toBe 1
atom.config.set("hair", "blonde") # trigger a save
expect(atom.config.save).not.toHaveBeenCalled()
@@ -692,7 +694,6 @@ describe "Config", ->
expect(atom.config.get(['.source.ruby'], 'foo.bar')).toBe 'baz'
expect(atom.config.get(['.source.ruby'], 'foo.scoped')).toBe true
describe "when the config file changes to omit a setting with a default", ->
it "resets the setting back to the default", ->
fs.writeFileSync(atom.config.configFilePath, "foo: { baz: 'new'}")

View File

@@ -724,21 +724,26 @@ class Config
@configFileHasErrors = false
catch error
@configFileHasErrors = true
console.error "Failed to load user config '#{@configFilePath}'", error.message
console.error error.stack
@notifyFailure('Failed to load user config', error)
observeUserConfig: ->
try
@watchSubscription ?= pathWatcher.watch @configFilePath, (eventType) =>
@loadUserConfig() if eventType is 'change' and @watchSubscription?
catch error
console.error "Failed to watch user config '#{@configFilePath}'", error.message
console.error error.stack
@notifyFailure('Failed to watch user config', error)
unobserveUserConfig: ->
@watchSubscription?.close()
@watchSubscription = null
notifyFailure: (errorMessage, error) ->
message = "#{errorMessage}"
detail = error.stack
atom.notifications.addError(message, {detail, closable: true})
console.error message
console.error detail
save: ->
allSettings = global: @settings
allSettings = _.extend allSettings, @scopedSettingsStore.propertiesForSource('user-config')