Consistent handling of ServerError exceptions
Previously we used the super-evil 'except Exception' clauses that would catch everything and turn debugging into a sanity-questioning exercise.
This commit is contained in:
parent
43b2dd44f2
commit
ba6c6182ed
@ -24,7 +24,10 @@ standard_library.install_aliases()
|
|||||||
from builtins import * # noqa
|
from builtins import * # noqa
|
||||||
|
|
||||||
import vim
|
import vim
|
||||||
from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError
|
from ycmd.responses import ServerError
|
||||||
|
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
||||||
|
HandleServerException )
|
||||||
|
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
from ycmd.utils import ToUnicode
|
from ycmd.utils import ToUnicode
|
||||||
|
|
||||||
@ -54,7 +57,7 @@ class CommandRequest( BaseRequest ):
|
|||||||
self._response = self.PostDataToHandler( request_data,
|
self._response = self.PostDataToHandler( request_data,
|
||||||
'run_completer_command' )
|
'run_completer_command' )
|
||||||
except ServerError as e:
|
except ServerError as e:
|
||||||
vimsupport.PostMultiLineNotice( e )
|
HandleServerException( e )
|
||||||
|
|
||||||
|
|
||||||
def Response( self ):
|
def Response( self ):
|
||||||
|
@ -25,6 +25,7 @@ from builtins import * # noqa
|
|||||||
|
|
||||||
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
||||||
HandleServerException )
|
HandleServerException )
|
||||||
|
from ycmd.responses import ServerError
|
||||||
|
|
||||||
class CompleterAvailableRequest( BaseRequest ):
|
class CompleterAvailableRequest( BaseRequest ):
|
||||||
def __init__( self, filetypes ):
|
def __init__( self, filetypes ):
|
||||||
@ -39,7 +40,7 @@ class CompleterAvailableRequest( BaseRequest ):
|
|||||||
try:
|
try:
|
||||||
self._response = self.PostDataToHandler( request_data,
|
self._response = self.PostDataToHandler( request_data,
|
||||||
'semantic_completion_available' )
|
'semantic_completion_available' )
|
||||||
except Exception as e:
|
except ServerError as e:
|
||||||
HandleServerException( e )
|
HandleServerException( e )
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ from ycmd.utils import ToUnicode
|
|||||||
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
|
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
|
||||||
HandleServerException,
|
HandleServerException,
|
||||||
MakeServerException )
|
MakeServerException )
|
||||||
|
from ycmd.responses import ServerError
|
||||||
|
|
||||||
TIMEOUT_SECONDS = 0.5
|
TIMEOUT_SECONDS = 0.5
|
||||||
|
|
||||||
@ -53,12 +54,12 @@ class CompletionRequest( BaseRequest ):
|
|||||||
try:
|
try:
|
||||||
response = JsonFromFuture( self._response_future )
|
response = JsonFromFuture( self._response_future )
|
||||||
|
|
||||||
errors = response['errors'] if 'errors' in response else []
|
errors = response[ 'errors' ] if 'errors' in response else []
|
||||||
for e in errors:
|
for e in errors:
|
||||||
HandleServerException( MakeServerException( e ) )
|
HandleServerException( MakeServerException( e ) )
|
||||||
|
|
||||||
return JsonFromFuture( self._response_future )[ 'completions' ]
|
return JsonFromFuture( self._response_future )[ 'completions' ]
|
||||||
except Exception as e:
|
except ServerError as e:
|
||||||
HandleServerException( e )
|
HandleServerException( e )
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ standard_library.install_aliases()
|
|||||||
from builtins import * # noqa
|
from builtins import * # noqa
|
||||||
|
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
from ycmd.responses import UnknownExtraConf
|
from ycmd.responses import UnknownExtraConf, ServerError
|
||||||
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
|
||||||
JsonFromFuture, HandleServerException )
|
JsonFromFuture, HandleServerException )
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class EventNotification( BaseRequest ):
|
|||||||
_LoadExtraConfFile( e.extra_conf_file )
|
_LoadExtraConfFile( e.extra_conf_file )
|
||||||
else:
|
else:
|
||||||
_IgnoreExtraConfFile( e.extra_conf_file )
|
_IgnoreExtraConfFile( e.extra_conf_file )
|
||||||
except Exception as e:
|
except ServerError as e:
|
||||||
HandleServerException( e )
|
HandleServerException( e )
|
||||||
|
|
||||||
return self._cached_response if self._cached_response else []
|
return self._cached_response if self._cached_response else []
|
||||||
|
@ -25,8 +25,9 @@ from builtins import * # noqa
|
|||||||
|
|
||||||
import vim
|
import vim
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
|
from ycmd.responses import ServerError
|
||||||
from ycmd.completers.completer import Completer
|
from ycmd.completers.completer import Completer
|
||||||
from ycm.client.base_request import BaseRequest, ServerError
|
from ycm.client.base_request import BaseRequest, HandleServerException
|
||||||
|
|
||||||
OMNIFUNC_RETURNED_BAD_VALUE = 'Omnifunc returned bad value to YCM!'
|
OMNIFUNC_RETURNED_BAD_VALUE = 'Omnifunc returned bad value to YCM!'
|
||||||
OMNIFUNC_NOT_LIST = ( 'Omnifunc did not return a list or a dict with a "words" '
|
OMNIFUNC_NOT_LIST = ( 'Omnifunc did not return a list or a dict with a "words" '
|
||||||
@ -114,5 +115,5 @@ class OmniCompleter( Completer ):
|
|||||||
return BaseRequest.PostDataToHandler( request_data,
|
return BaseRequest.PostDataToHandler( request_data,
|
||||||
'filter_and_sort_candidates' )
|
'filter_and_sort_candidates' )
|
||||||
except ServerError as e:
|
except ServerError as e:
|
||||||
vimsupport.PostMultiLineNotice( e )
|
HandleServerException( e )
|
||||||
return candidates
|
return candidates
|
||||||
|
@ -33,7 +33,7 @@ from ycm.youcompleteme import YouCompleteMe
|
|||||||
from ycm.client.base_request import YCMD_ERROR_PREFIX
|
from ycm.client.base_request import YCMD_ERROR_PREFIX
|
||||||
from ycmd import user_options_store
|
from ycmd import user_options_store
|
||||||
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
|
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
|
||||||
UnknownExtraConf )
|
UnknownExtraConf, ServerError )
|
||||||
|
|
||||||
from mock import call, MagicMock, patch
|
from mock import call, MagicMock, patch
|
||||||
from nose.tools import eq_, ok_
|
from nose.tools import eq_, ok_
|
||||||
@ -183,7 +183,7 @@ class EventNotification_test( object ):
|
|||||||
ERROR_TEXT = 'Some completer response text'
|
ERROR_TEXT = 'Some completer response text'
|
||||||
|
|
||||||
def ErrorResponse( *args ):
|
def ErrorResponse( *args ):
|
||||||
raise RuntimeError( ERROR_TEXT )
|
raise ServerError( ERROR_TEXT )
|
||||||
|
|
||||||
with MockArbitraryBuffer( 'javascript' ):
|
with MockArbitraryBuffer( 'javascript' ):
|
||||||
with MockEventNotification( ErrorResponse ):
|
with MockEventNotification( ErrorResponse ):
|
||||||
|
Loading…
Reference in New Issue
Block a user