Add docstring to HandleServerException

Wrap request with HandleServerException in YcmdKeepalive class.
This commit is contained in:
micbou 2016-12-12 01:31:49 +01:00
parent 01aa54ee2d
commit 85d5844873
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
4 changed files with 18 additions and 6 deletions

View File

@ -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:

0
python/ycm/client/debug_info_request.py Executable file → Normal file
View File

View File

@ -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
python/ycm/tests/command_test.py Executable file → Normal file
View File