Add docstring to HandleServerException
Wrap request with HandleServerException in YcmdKeepalive class.
This commit is contained in:
parent
01aa54ee2d
commit
85d5844873
@ -198,6 +198,22 @@ def JsonFromFuture( future ):
|
|||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def HandleServerException( display = True, truncate = False ):
|
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:
|
try:
|
||||||
yield
|
yield
|
||||||
except UnknownExtraConf as e:
|
except UnknownExtraConf as e:
|
||||||
|
0
python/ycm/client/debug_info_request.py
Executable file → Normal file
0
python/ycm/client/debug_info_request.py
Executable file → Normal file
@ -25,7 +25,7 @@ from builtins import * # noqa
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
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
|
# 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:
|
while True:
|
||||||
time.sleep( self._ping_interval_seconds )
|
time.sleep( self._ping_interval_seconds )
|
||||||
|
|
||||||
# We don't care if there's an intermittent problem in contacting the
|
with HandleServerException( display = False ):
|
||||||
# server; it's fine to just skip this ping.
|
|
||||||
try:
|
|
||||||
BaseRequest.GetDataFromHandler( 'healthy' )
|
BaseRequest.GetDataFromHandler( 'healthy' )
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
0
python/ycm/tests/command_test.py
Executable file → Normal file
0
python/ycm/tests/command_test.py
Executable file → Normal file
Loading…
Reference in New Issue
Block a user