diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 15dc3b8fa..4abd3b0db 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -666,6 +666,23 @@ describe "Config", -> foo: bar: 'coffee' + describe "when an error is thrown writing the file to disk", -> + addErrorHandler = null + beforeEach -> + atom.notifications.onDidAddNotification addErrorHandler = jasmine.createSpy() + + it "creates a notification", -> + jasmine.unspy CSON, 'writeFileSync' + spyOn(CSON, 'writeFileSync').andCallFake -> + error = new Error() + error.code = 'EPERM' + error.path = atom.config.getUserConfigPath() + throw error + + save = -> atom.config.save() + expect(save).not.toThrow() + expect(addErrorHandler.callCount).toBe 1 + describe ".loadUserConfig()", -> beforeEach -> expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy() diff --git a/src/config.coffee b/src/config.coffee index d9695fb55..937bb1307 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -868,7 +868,12 @@ class Config save: -> allSettings = {'*': @settings} allSettings = _.extend allSettings, @scopedSettingsStore.propertiesForSource(@getUserConfigPath()) - CSON.writeFileSync(@configFilePath, allSettings) + try + CSON.writeFileSync(@configFilePath, allSettings) + catch error + message = "Failed to save `#{path.basename(@configFilePath)}`" + detail = error.message + @notifyFailure(message, detail) ### Section: Private methods managing global settings