Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
catch some unhandled error
Browse files Browse the repository at this point in the history
  • Loading branch information
Qusic committed May 16, 2016
1 parent c4d5b88 commit 5e66adf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/event.coffee
Expand Up @@ -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) ->
Expand Down
4 changes: 2 additions & 2 deletions lib/handler.coffee
Expand Up @@ -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.'
Expand Down
5 changes: 3 additions & 2 deletions lib/menu.coffee
Expand Up @@ -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]
Expand Down
8 changes: 2 additions & 6 deletions lib/provider.coffee
Expand Up @@ -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 []
5 changes: 5 additions & 0 deletions lib/utility.coffee
Expand Up @@ -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()

Expand All @@ -55,4 +59,5 @@ module.exports =
getScopeFiletypes: getScopeFiletypes
buildRequestParameters: buildRequestParameters
isEnabledForScope: isEnabledForScope
notifyError: notifyError
debugLog: debugLog

0 comments on commit 5e66adf

Please sign in to comment.