1
0
Эх сурвалжийг харах

Add docstring to HandleServerException

Wrap request with HandleServerException in YcmdKeepalive class.
micbou 8 жил өмнө
parent
commit
85d5844873

+ 16 - 0
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:

+ 2 - 6
python/ycm/client/debug_info_request.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

+ 0 - 0
python/ycm/tests/command_test.py