Skip to content

Commit

Permalink
Show server crashed dialog on unexpected output in server's stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored and rwols committed Jul 6, 2023
1 parent d4ba30d commit 75bd043
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plugin/core/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ def read_data(self, reader: IO[bytes]) -> Optional[Dict[str, Any]]:
try:
body = reader.read(int(headers.get("Content-Length")))
except TypeError:
# Expected error on process stopping. Stop the read loop.
raise StopLoopError()
if str(headers) == '\n':
# Expected on process stopping. Gracefully stop the transport.
raise StopLoopError()
else:
# Propagate server's output to the UI.
raise Exception("Unexpected payload in server's stdout:\n\n{}".format(headers))
try:
return self._decode(body)
except Exception as ex:
exception_log("JSON decode error", ex)
return None
raise Exception("JSON decode error: {}".format(ex))

@staticmethod
def _encode(data: Dict[str, Any]) -> bytes:
Expand Down Expand Up @@ -135,6 +138,7 @@ def __del__(self) -> None:
self._join_thread(self._stderr_thread)

def _read_loop(self) -> None:
exception = None
try:
while self._reader:
payload = self._processor.read_data(self._reader)
Expand All @@ -152,8 +156,11 @@ def invoke(p: T) -> None:
except (AttributeError, BrokenPipeError, StopLoopError):
pass
except Exception as ex:
exception_log("Unexpected exception", ex)
self._send_queue.put_nowait(None)
exception = ex
if exception:
self._end(exception)
else:
self._send_queue.put_nowait(None)

def _end(self, exception: Optional[Exception]) -> None:
exit_code = 0
Expand Down

0 comments on commit 75bd043

Please sign in to comment.