Skip to content

Commit

Permalink
Consistent handling of ServerError exceptions
Browse files Browse the repository at this point in the history
Previously we used the super-evil 'except Exception' clauses that would
catch everything and turn debugging into a sanity-questioning exercise.
  • Loading branch information
Valloric committed Feb 29, 2016
1 parent 43b2dd4 commit ba6c618
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions python/ycm/client/command_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
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

Expand Down Expand Up @@ -54,7 +57,7 @@ def Start( self ):
self._response = self.PostDataToHandler( request_data,
'run_completer_command' )
except ServerError as e:
vimsupport.PostMultiLineNotice( e )
HandleServerException( e )


def Response( self ):
Expand Down
3 changes: 2 additions & 1 deletion python/ycm/client/completer_available_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from ycm.client.base_request import ( BaseRequest, BuildRequestData,
HandleServerException )
from ycmd.responses import ServerError

class CompleterAvailableRequest( BaseRequest ):
def __init__( self, filetypes ):
Expand All @@ -39,7 +40,7 @@ def Start( self ):
try:
self._response = self.PostDataToHandler( request_data,
'semantic_completion_available' )
except Exception as e:
except ServerError as e:
HandleServerException( e )


Expand Down
5 changes: 3 additions & 2 deletions python/ycm/client/completion_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
HandleServerException,
MakeServerException )
from ycmd.responses import ServerError

TIMEOUT_SECONDS = 0.5

Expand All @@ -53,12 +54,12 @@ def RawResponse( self ):
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 []

Expand Down
4 changes: 2 additions & 2 deletions python/ycm/client/event_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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 )

Expand Down Expand Up @@ -66,7 +66,7 @@ def Response( self ):
_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 []
Expand Down
5 changes: 3 additions & 2 deletions python/ycm/omni_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

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" '
Expand Down Expand Up @@ -114,5 +115,5 @@ def FilterAndSortCandidatesInner( self, candidates, sort_property, query ):
return BaseRequest.PostDataToHandler( request_data,
'filter_and_sort_candidates' )
except ServerError as e:
vimsupport.PostMultiLineNotice( e )
HandleServerException( e )
return candidates
4 changes: 2 additions & 2 deletions python/ycm/tests/event_notification_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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_
Expand Down Expand Up @@ -183,7 +183,7 @@ def FileReadyToParse_NonDiagnostic_Error_test( self, vim_command ):
ERROR_TEXT = 'Some completer response text'

def ErrorResponse( *args ):
raise RuntimeError( ERROR_TEXT )
raise ServerError( ERROR_TEXT )

with MockArbitraryBuffer( 'javascript' ):
with MockEventNotification( ErrorResponse ):
Expand Down

0 comments on commit ba6c618

Please sign in to comment.