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:
Val Markovic 2016-02-28 16:01:59 -08:00
parent 43b2dd44f2
commit ba6c6182ed
6 changed files with 17 additions and 11 deletions

View File

@ -24,7 +24,10 @@ standard_library.install_aliases()
from builtins import * # noqa
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 ycmd.utils import ToUnicode
@ -54,7 +57,7 @@ class CommandRequest( BaseRequest ):
self._response = self.PostDataToHandler( request_data,
'run_completer_command' )
except ServerError as e:
vimsupport.PostMultiLineNotice( e )
HandleServerException( e )
def Response( self ):

View File

@ -25,6 +25,7 @@ from builtins import * # noqa
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
HandleServerException )
from ycmd.responses import ServerError
class CompleterAvailableRequest( BaseRequest ):
def __init__( self, filetypes ):
@ -39,7 +40,7 @@ class CompleterAvailableRequest( BaseRequest ):
try:
self._response = self.PostDataToHandler( request_data,
'semantic_completion_available' )
except Exception as e:
except ServerError as e:
HandleServerException( e )

View File

@ -27,6 +27,7 @@ from ycmd.utils import ToUnicode
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
HandleServerException,
MakeServerException )
from ycmd.responses import ServerError
TIMEOUT_SECONDS = 0.5
@ -53,12 +54,12 @@ class CompletionRequest( BaseRequest ):
try:
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:
HandleServerException( MakeServerException( e ) )
return JsonFromFuture( self._response_future )[ 'completions' ]
except Exception as e:
except ServerError as e:
HandleServerException( e )
return []

View File

@ -24,7 +24,7 @@ standard_library.install_aliases()
from builtins import * # noqa
from ycm import vimsupport
from ycmd.responses import UnknownExtraConf
from ycmd.responses import UnknownExtraConf, ServerError
from ycm.client.base_request import ( BaseRequest, BuildRequestData,
JsonFromFuture, HandleServerException )
@ -66,7 +66,7 @@ class EventNotification( BaseRequest ):
_LoadExtraConfFile( e.extra_conf_file )
else:
_IgnoreExtraConfFile( e.extra_conf_file )
except Exception as e:
except ServerError as e:
HandleServerException( e )
return self._cached_response if self._cached_response else []

View File

@ -25,8 +25,9 @@ from builtins import * # noqa
import vim
from ycm import vimsupport
from ycmd.responses import ServerError
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_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,
'filter_and_sort_candidates' )
except ServerError as e:
vimsupport.PostMultiLineNotice( e )
HandleServerException( e )
return candidates

View File

@ -33,7 +33,7 @@ from ycm.youcompleteme import YouCompleteMe
from ycm.client.base_request import YCMD_ERROR_PREFIX
from ycmd import user_options_store
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
UnknownExtraConf )
UnknownExtraConf, ServerError )
from mock import call, MagicMock, patch
from nose.tools import eq_, ok_
@ -183,7 +183,7 @@ class EventNotification_test( object ):
ERROR_TEXT = 'Some completer response text'
def ErrorResponse( *args ):
raise RuntimeError( ERROR_TEXT )
raise ServerError( ERROR_TEXT )
with MockArbitraryBuffer( 'javascript' ):
with MockEventNotification( ErrorResponse ):