diff --git a/lib/event.coffee b/lib/event.coffee index 94fcdee..288259e 100644 --- a/lib/event.coffee +++ b/lib/event.coffee @@ -10,7 +10,7 @@ emitEvent = (editor, name, args) -> parameters = utility.buildRequestParameters filepath, contents, filetypes parameters.event_name = name parameters[key] = value for key, value of args - handler.request('POST', 'event_notification', parameters) + handler.request('POST', 'event_notification', parameters).catch utility.notifyError() observeEditors = -> atom.workspace.observeTextEditors (editor) -> diff --git a/lib/handler.coffee b/lib/handler.coffee index 800e5e7..442d896 100644 --- a/lib/handler.coffee +++ b/lib/handler.coffee @@ -125,8 +125,8 @@ request = (method, endpoint, parameters = null) -> prepare().then -> message: '[YCM] Unknown Extra Config' detailedMessage: message buttons: - Load: -> request 'POST', 'load_extra_conf_file', {filepath} - Ignore: -> request 'POST', 'ignore_extra_conf_file', {filepath} + Load: -> request('POST', 'load_extra_conf_file', {filepath}).catch utility.notifyError() + Ignore: -> request('POST', 'ignore_extra_conf_file', {filepath}).catch utility.notifyError() shouldIgnore = -> response.message is 'File already being parsed.' diff --git a/lib/menu.coffee b/lib/menu.coffee index 2ad8ee8..796af38 100644 --- a/lib/menu.coffee +++ b/lib/menu.coffee @@ -29,8 +29,9 @@ runCommand = (command) -> register = -> generatedCommands = {} generatedMenus = [] - for key, command of commands - generatedCommands["you-complete-me:#{key}"] = ((command) -> (event) -> runCommand command)(command) + Object.keys(commands).forEach (key) -> + command = commands[key] + generatedCommands["you-complete-me:#{key}"] = (event) -> runCommand(command).catch utility.notifyError() generatedMenus.push command: "you-complete-me:#{key}", label: command atom.commands.add 'atom-text-editor', generatedCommands contextMenu = atom.contextMenu.add 'atom-text-editor': [label: 'YouCompleteMe', submenu: generatedMenus] diff --git a/lib/provider.coffee b/lib/provider.coffee index d9387bc..6f33957 100644 --- a/lib/provider.coffee +++ b/lib/provider.coffee @@ -14,12 +14,8 @@ module.exports = getSuggestions: (context) -> return [] unless utility.isEnabledForScope context.scopeDescriptor - getCompletions(context).catch (error) -> - console.error '[YCM-ERROR]', error - return [] + getCompletions(context).catch utility.notifyError [] lint: (editor) -> return [] unless utility.isEnabledForScope editor.getRootScopeDescriptor() - getIssues(editor).catch (error) -> - console.error '[YCM-ERROR]', error - return [] + getIssues(editor).catch utility.notifyError [] diff --git a/lib/utility.coffee b/lib/utility.coffee index 278618a..a2b332c 100644 --- a/lib/utility.coffee +++ b/lib/utility.coffee @@ -46,6 +46,10 @@ isEnabledForScope = (scopeDescriptor) -> filetype = filetypes.find (filetype) -> enabledFiletypes.indexOf(filetype) >= 0 return if filetype? then true else false +notifyError = (result) -> (error) -> + atom.notifications.addError "[YCM] #{error.name}", detail: "#{error.stack}" + result + debugLog = (category, message...) -> console.debug "[YCM-#{category}]", message... if atom.inDevMode() @@ -55,4 +59,5 @@ module.exports = getScopeFiletypes: getScopeFiletypes buildRequestParameters: buildRequestParameters isEnabledForScope: isEnabledForScope + notifyError: notifyError debugLog: debugLog