From 3d55b2d826bc5fbac5ab8d42869519290d8d6d72 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 5 Aug 2018 12:50:17 +0200 Subject: [PATCH] Subprocess error reporting improvements --- jedi/evaluate/compiled/subprocess/__init__.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/jedi/evaluate/compiled/subprocess/__init__.py b/jedi/evaluate/compiled/subprocess/__init__.py index 5a9a52fd..420e048f 100644 --- a/jedi/evaluate/compiled/subprocess/__init__.py +++ b/jedi/evaluate/compiled/subprocess/__init__.py @@ -22,7 +22,7 @@ except ImportError: from Queue import Queue, Empty # python 2.7 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.cache import memoize_method from jedi.evaluate.compiled.subprocess import functions @@ -40,6 +40,18 @@ def _enqueue_output(out, queue): 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): return getattr(functions, name) @@ -229,10 +241,11 @@ class CompiledSubprocess(object): is_exception, traceback, result = pickle_load(self._process.stdout) except EOFError as eof_error: try: - stderr = self._process.stderr.read() + stderr = self._process.stderr.read().decode('utf-8', 'replace') except Exception as exc: stderr = '' % exc self._kill() + _add_stderr_to_debug(self._stderr_queue) raise InternalError( "The subprocess %s has crashed (%r, stderr=%s)." % ( self._executable, @@ -240,15 +253,7 @@ class CompiledSubprocess(object): stderr, )) - while True: - # 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 + _add_stderr_to_debug(self._stderr_queue) if is_exception: # Replace the attribute error message with a the traceback. It's