From 85d58448732b46359db3e38b862ba935d7c3bb02 Mon Sep 17 00:00:00 2001 From: micbou Date: Mon, 12 Dec 2016 01:31:49 +0100 Subject: [PATCH] Add docstring to HandleServerException Wrap request with HandleServerException in YcmdKeepalive class. --- python/ycm/client/base_request.py | 16 ++++++++++++++++ python/ycm/client/debug_info_request.py | 0 python/ycm/client/ycmd_keepalive.py | 8 ++------ python/ycm/tests/command_test.py | 0 4 files changed, 18 insertions(+), 6 deletions(-) mode change 100755 => 100644 python/ycm/client/debug_info_request.py mode change 100755 => 100644 python/ycm/tests/command_test.py 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