diff --git a/python/ycm/client/base_request.py b/python/ycm/client/base_request.py index d158c633..17934eb8 100644 --- a/python/ycm/client/base_request.py +++ b/python/ycm/client/base_request.py @@ -198,6 +198,22 @@ def JsonFromFuture( future ): @contextlib.contextmanager 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: diff --git a/python/ycm/client/debug_info_request.py b/python/ycm/client/debug_info_request.py old mode 100755 new mode 100644 diff --git a/python/ycm/client/ycmd_keepalive.py b/python/ycm/client/ycmd_keepalive.py index fca59f42..ecf5fe39 100644 --- a/python/ycm/client/ycmd_keepalive.py +++ b/python/ycm/client/ycmd_keepalive.py @@ -25,7 +25,7 @@ from builtins import * # noqa import time from threading import Thread -from ycm.client.base_request import BaseRequest +from ycm.client.base_request import BaseRequest, HandleServerException # This class can be used to keep the ycmd server alive for the duration of the @@ -46,9 +46,5 @@ class YcmdKeepalive( object ): while True: time.sleep( self._ping_interval_seconds ) - # We don't care if there's an intermittent problem in contacting the - # server; it's fine to just skip this ping. - try: + with HandleServerException( display = False ): BaseRequest.GetDataFromHandler( 'healthy' ) - except: - pass diff --git a/python/ycm/tests/command_test.py b/python/ycm/tests/command_test.py old mode 100755 new mode 100644