Improve error message when server crashes
Give the exact command that the user needs to type to open the server logfile when the server unexpectedly crashes.
This commit is contained in:
parent
9a76fd2e9a
commit
031edea89e
@ -28,7 +28,7 @@ MockVimModule()
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from hamcrest import ( assert_that, contains, empty, is_in, is_not, has_length,
|
from hamcrest import ( assert_that, contains, empty, equal_to, is_in, is_not,
|
||||||
matches_regexp )
|
matches_regexp )
|
||||||
from mock import call, MagicMock, patch
|
from mock import call, MagicMock, patch
|
||||||
|
|
||||||
@ -53,23 +53,19 @@ def RunNotifyUserIfServerCrashed( ycm, test, post_vim_message ):
|
|||||||
|
|
||||||
ycm._NotifyUserIfServerCrashed()
|
ycm._NotifyUserIfServerCrashed()
|
||||||
|
|
||||||
assert_that( ycm._logger.method_calls,
|
assert_that( ycm._logger.error.call_args[ 0 ][ 0 ],
|
||||||
has_length( len( test[ 'expected_logs' ] ) ) )
|
test[ 'expected_message' ] )
|
||||||
ycm._logger.error.assert_has_calls(
|
assert_that( post_vim_message.call_args[ 0 ][ 0 ],
|
||||||
[ call( log ) for log in test[ 'expected_logs' ] ] )
|
test[ 'expected_message' ] )
|
||||||
post_vim_message.assert_has_exact_calls( [
|
|
||||||
call( test[ 'expected_vim_message' ] )
|
|
||||||
] )
|
|
||||||
|
|
||||||
|
|
||||||
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedCore_test():
|
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedCore_test():
|
||||||
message = ( "The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
|
message = ( "The ycmd server SHUT DOWN \(restart with ':YcmRestartServer'\). "
|
||||||
"Unexpected error while loading the YCM core library. "
|
"Unexpected error while loading the YCM core library. Type "
|
||||||
"Use the ':YcmToggleLogs' command to check the logs." )
|
"':YcmToggleLogs ycmd_\d+_stderr_.+.log' to check the logs." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 3,
|
'return_code': 3,
|
||||||
'expected_logs': [ message ],
|
'expected_message': matches_regexp( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
@ -79,8 +75,7 @@ def YouCompleteMe_NotifyUserIfServerCrashed_MissingCore_test():
|
|||||||
"using it. Follow the instructions in the documentation." )
|
"using it. Follow the instructions in the documentation." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 4,
|
'return_code': 4,
|
||||||
'expected_logs': [ message ],
|
'expected_message': equal_to( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
@ -91,8 +86,7 @@ def YouCompleteMe_NotifyUserIfServerCrashed_Python2Core_test():
|
|||||||
"interpreter path." )
|
"interpreter path." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 5,
|
'return_code': 5,
|
||||||
'expected_logs': [ message ],
|
'expected_message': equal_to( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
@ -103,8 +97,7 @@ def YouCompleteMe_NotifyUserIfServerCrashed_Python3Core_test():
|
|||||||
"interpreter path." )
|
"interpreter path." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 6,
|
'return_code': 6,
|
||||||
'expected_logs': [ message ],
|
'expected_message': equal_to( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
@ -114,19 +107,17 @@ def YouCompleteMe_NotifyUserIfServerCrashed_OutdatedCore_test():
|
|||||||
"install.py script. See the documentation for more details." )
|
"install.py script. See the documentation for more details." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 7,
|
'return_code': 7,
|
||||||
'expected_logs': [ message ],
|
'expected_message': equal_to( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test():
|
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test():
|
||||||
message = ( "The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). "
|
message = ( "The ycmd server SHUT DOWN \(restart with ':YcmRestartServer'\). "
|
||||||
"Unexpected exit code 1. Use the ':YcmToggleLogs' command to "
|
"Unexpected exit code 1. Type "
|
||||||
"check the logs." )
|
"':YcmToggleLogs ycmd_\d+_stderr_.+.log' to check the logs." )
|
||||||
RunNotifyUserIfServerCrashed( {
|
RunNotifyUserIfServerCrashed( {
|
||||||
'return_code': 1,
|
'return_code': 1,
|
||||||
'expected_logs': [ message ],
|
'expected_message': matches_regexp( message )
|
||||||
'expected_vim_message': message
|
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,10 +79,10 @@ SERVER_SHUTDOWN_MESSAGE = (
|
|||||||
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer')." )
|
"The ycmd server SHUT DOWN (restart with ':YcmRestartServer')." )
|
||||||
EXIT_CODE_UNEXPECTED_MESSAGE = (
|
EXIT_CODE_UNEXPECTED_MESSAGE = (
|
||||||
"Unexpected exit code {code}. "
|
"Unexpected exit code {code}. "
|
||||||
"Use the ':YcmToggleLogs' command to check the logs." )
|
"Type ':YcmToggleLogs {logfile}' to check the logs." )
|
||||||
CORE_UNEXPECTED_MESSAGE = (
|
CORE_UNEXPECTED_MESSAGE = (
|
||||||
"Unexpected error while loading the YCM core library. "
|
"Unexpected error while loading the YCM core library. "
|
||||||
"Use the ':YcmToggleLogs' command to check the logs." )
|
"Type ':YcmToggleLogs {logfile}' to check the logs." )
|
||||||
CORE_MISSING_MESSAGE = (
|
CORE_MISSING_MESSAGE = (
|
||||||
'YCM core library not detected; you need to compile YCM before using it. '
|
'YCM core library not detected; you need to compile YCM before using it. '
|
||||||
'Follow the instructions in the documentation.' )
|
'Follow the instructions in the documentation.' )
|
||||||
@ -238,8 +238,10 @@ class YouCompleteMe( object ):
|
|||||||
self._user_notified_about_crash = True
|
self._user_notified_about_crash = True
|
||||||
|
|
||||||
return_code = self._server_popen.poll()
|
return_code = self._server_popen.poll()
|
||||||
|
logfile = os.path.basename( self._server_stderr )
|
||||||
if return_code == server_utils.CORE_UNEXPECTED_STATUS:
|
if return_code == server_utils.CORE_UNEXPECTED_STATUS:
|
||||||
error_message = CORE_UNEXPECTED_MESSAGE
|
error_message = CORE_UNEXPECTED_MESSAGE.format(
|
||||||
|
logfile = logfile )
|
||||||
elif return_code == server_utils.CORE_MISSING_STATUS:
|
elif return_code == server_utils.CORE_MISSING_STATUS:
|
||||||
error_message = CORE_MISSING_MESSAGE
|
error_message = CORE_MISSING_MESSAGE
|
||||||
elif return_code == server_utils.CORE_PYTHON2_STATUS:
|
elif return_code == server_utils.CORE_PYTHON2_STATUS:
|
||||||
@ -249,7 +251,9 @@ class YouCompleteMe( object ):
|
|||||||
elif return_code == server_utils.CORE_OUTDATED_STATUS:
|
elif return_code == server_utils.CORE_OUTDATED_STATUS:
|
||||||
error_message = CORE_OUTDATED_MESSAGE
|
error_message = CORE_OUTDATED_MESSAGE
|
||||||
else:
|
else:
|
||||||
error_message = EXIT_CODE_UNEXPECTED_MESSAGE.format( code = return_code )
|
error_message = EXIT_CODE_UNEXPECTED_MESSAGE.format(
|
||||||
|
code = return_code,
|
||||||
|
logfile = logfile )
|
||||||
|
|
||||||
error_message = SERVER_SHUTDOWN_MESSAGE + ' ' + error_message
|
error_message = SERVER_SHUTDOWN_MESSAGE + ' ' + error_message
|
||||||
self._logger.error( error_message )
|
self._logger.error( error_message )
|
||||||
|
Loading…
Reference in New Issue
Block a user