def HandleServerException( display = True, truncate = False ): """Catch any exception raised through server communication. If it is raised because of a unknown .ycm_extra_conf.py file, load the file or ignore it after asking the user. Otherwise, log the exception and display its message to the user on the Vim status line. Unset the |display| parameter to hide the message from the user. Set the |truncate| parameter to avoid hit-enter prompts from this message. The GetDataFromHandler, PostDataToHandler, and JsonFromFuture functions should always be wrapped by this function to avoid Python exceptions bubbling up to the user. Example usage: with HandleServerException(): response = BaseRequest.PostDataToHandler( ... ) """ try: yield except UnknownExtraConf as e: if vimsupport.Confirm( str( e ) ): _LoadExtraConfFile( e.extra_conf_file ) else: _IgnoreExtraConfFile( e.extra_conf_file ) except Exception as e: _logger.exception( 'Error while handling server response' ) if display: DisplayServerException( e, truncate )
def HandleFuture(self, future, display_message=True, truncate_message=False): """Get the server response from a |future| object and catch any exception while doing so. If an exception is raised because of a unknown .ycm_extra_conf.py file, load the file or ignore it after asking the user. An identical request should be sent again to the server. For other exceptions, log the exception and display its message to the user on the Vim status line. Unset the |display_message| parameter to hide the message from the user. Set the |truncate_message| parameter to avoid hit-enter prompts from this message.""" try: try: result = _JsonFromFuture(future) _logger.debug('RX: %s', result) return result except UnknownExtraConf as e: if vimsupport.Confirm(str(e)): _LoadExtraConfFile(e.extra_conf_file) else: _IgnoreExtraConfFile(e.extra_conf_file) self._should_resend = True except BaseRequest.Requests().exceptions.ConnectionError as e: # We don't display this exception to the user since it is likely to happen # for each subsequent request (typically if the server crashed) and we # don't want to spam the user with it. _logger.error(e) except Exception as e: _logger.exception('Error while handling server response') if display_message: DisplayServerException(e, truncate_message) return None
def _ShouldLoad(module_file): """Checks if a module is safe to be loaded. By default this will try to decide using a white-/blacklist and ask the user for confirmation as a fallback.""" if (module_file == GLOBAL_YCM_EXTRA_CONF_FILE or not vimsupport.GetBoolValue('g:ycm_confirm_extra_conf')): return True globlist = vimsupport.GetVariableValue('g:ycm_extra_conf_globlist') for glob in globlist: is_blacklisted = glob[0] == '!' if _MatchesGlobPattern(module_file, glob.lstrip('!')): return not is_blacklisted return vimsupport.Confirm(CONFIRM_CONF_FILE_MESSAGE.format(module_file))
def Response(self): if self._cached_response: return self._cached_response if not self._response_future or self._event_name != 'FileReadyToParse': return [] try: try: self._cached_response = JsonFromFuture(self._response_future) except UnknownExtraConf as e: if vimsupport.Confirm(str(e)): _LoadExtraConfFile(e.extra_conf_file) else: _IgnoreExtraConfFile(e.extra_conf_file) except Exception as e: HandleServerException(e) return self._cached_response if self._cached_response else []
def Response(self): if self._cached_response: return self._cached_response if not self._response_future or self._event_name != 'FileReadyToParse': return [] try: try: self._cached_response = JsonFromFuture(self._response_future) except UnknownExtraConf as e: if vimsupport.Confirm(str(e)): _LoadExtraConfFile(e.extra_conf_file) except Exception as e: vimsupport.PostVimMessage(str(e)) if not self._cached_response: return [] self._cached_response = [ _ConvertDiagnosticDataToVimData(x) for x in self._cached_response ] return self._cached_response