Subprocess error reporting improvements

This commit is contained in:
Dave Halter
2018-08-05 12:50:17 +02:00
parent 1547177128
commit 3d55b2d826
+16 -11
View File
@@ -22,7 +22,7 @@ except ImportError:
from Queue import Queue, Empty # python 2.7 from Queue import Queue, Empty # python 2.7
from jedi._compatibility import queue, is_py3, force_unicode, \ from jedi._compatibility import queue, is_py3, force_unicode, \
pickle_dump, pickle_load, GeneralizedPopen pickle_dump, pickle_load, GeneralizedPopen, print_to_stderr
from jedi import debug from jedi import debug
from jedi.cache import memoize_method from jedi.cache import memoize_method
from jedi.evaluate.compiled.subprocess import functions from jedi.evaluate.compiled.subprocess import functions
@@ -40,6 +40,18 @@ def _enqueue_output(out, queue):
out.close() out.close()
def _add_stderr_to_debug(stderr_queue):
while True:
# Try to do some error reporting from the subprocess and print its
# stderr contents.
try:
line = stderr_queue.get_nowait()
line = line.decode('utf-8', 'replace')
debug.warning('stderr output: %s' % line.rstrip('\n'))
except Empty:
break
def _get_function(name): def _get_function(name):
return getattr(functions, name) return getattr(functions, name)
@@ -229,10 +241,11 @@ class CompiledSubprocess(object):
is_exception, traceback, result = pickle_load(self._process.stdout) is_exception, traceback, result = pickle_load(self._process.stdout)
except EOFError as eof_error: except EOFError as eof_error:
try: try:
stderr = self._process.stderr.read() stderr = self._process.stderr.read().decode('utf-8', 'replace')
except Exception as exc: except Exception as exc:
stderr = '<empty/not available (%r)>' % exc stderr = '<empty/not available (%r)>' % exc
self._kill() self._kill()
_add_stderr_to_debug(self._stderr_queue)
raise InternalError( raise InternalError(
"The subprocess %s has crashed (%r, stderr=%s)." % ( "The subprocess %s has crashed (%r, stderr=%s)." % (
self._executable, self._executable,
@@ -240,15 +253,7 @@ class CompiledSubprocess(object):
stderr, stderr,
)) ))
while True: _add_stderr_to_debug(self._stderr_queue)
# Try to do some error reporting from the subprocess and print its
# stderr contents.
try:
line = self._stderr_queue.get_nowait()
line = line.decode('utf-8', 'replace')
debug.warning('stderr output: %s' % line.rstrip('\n'))
except Empty:
break
if is_exception: if is_exception:
# Replace the attribute error message with a the traceback. It's # Replace the attribute error message with a the traceback. It's