diff --git a/mypy/build.py b/mypy/build.py index d4038cd5c0aa..f7e13cfb5791 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -242,22 +242,26 @@ def __init__(self, status_file: str, options_data: str, env: Mapping[str, str]) def connect(self) -> None: end_time = time.time() + WORKER_START_TIMEOUT + last_exception: Exception | None = None while time.time() < end_time: try: data = read_status(self.status_file) - except BadStatus: + except BadStatus as exc: + last_exception = exc time.sleep(WORKER_START_INTERVAL) continue try: pid, connection_name = data["pid"], data["connection_name"] - assert isinstance(pid, int) and isinstance(connection_name, str) + assert isinstance(pid, int), f"Bad PID: {pid}" + assert isinstance(connection_name, str), f"Bad connection name: {connection_name}" # Double-check this status file is created by us. - assert pid == self.proc.pid + assert pid == self.proc.pid, f"PID mismatch: {pid} vs {self.proc.pid}" self.conn = IPCClient(connection_name, WORKER_CONNECTION_TIMEOUT) return - except Exception: + except Exception as exc: + last_exception = exc break - print("Failed to establish connection with worker") + print("Failed to establish connection with worker:", last_exception) sys.exit(2) def close(self) -> None: diff --git a/mypy/build_worker/worker.py b/mypy/build_worker/worker.py index 049f5e44256a..86a0da3b6c7f 100644 --- a/mypy/build_worker/worker.py +++ b/mypy/build_worker/worker.py @@ -92,8 +92,9 @@ def main(argv: list[str]) -> None: try: with server: serve(server, ctx) - except OSError: - pass + except OSError as exc: + if options.verbosity >= 1: + print("Error communicating with coordinator:", exc) except Exception as exc: report_internal_error(exc, errors.file, 0, errors, options) finally: diff --git a/mypy/ipc.py b/mypy/ipc.py index f3b250711181..e21171d46b0f 100644 --- a/mypy/ipc.py +++ b/mypy/ipc.py @@ -350,7 +350,7 @@ def read_status(status_file: str) -> dict[str, object]: except Exception as e: raise BadStatus("Malformed status file (not JSON)") from e if not isinstance(data, dict): - raise BadStatus("Invalid status file (not a dict)") + raise BadStatus(f"Invalid status file (not a dict): {data}") return data