Skip to content

Show logging written to stderr in mypy daemon #14775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,15 @@ def request(
return {"error": str(err)}
# TODO: Other errors, e.g. ValueError, UnicodeError
else:
# Display debugging output written to stdout in the server process for convenience.
# Display debugging output written to stdout/stderr in the server process for convenience.
stdout = response.get("stdout")
if stdout:
sys.stdout.write(stdout)
stderr = response.get("stderr")
if stderr:
print("-" * 79)
print("stderr:")
sys.stdout.write(stderr)
return response


Expand Down
4 changes: 4 additions & 0 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def serve(self) -> None:
with server:
data = receive(server)
debug_stdout = io.StringIO()
debug_stderr = io.StringIO()
sys.stdout = debug_stdout
sys.stderr = debug_stderr
resp: dict[str, Any] = {}
if "command" not in data:
resp = {"error": "No command found in request"}
Expand All @@ -233,9 +235,11 @@ def serve(self) -> None:
resp = {"error": "Daemon crashed!\n" + "".join(tb)}
resp.update(self._response_metadata())
resp["stdout"] = debug_stdout.getvalue()
resp["stderr"] = debug_stderr.getvalue()
server.write(json.dumps(resp).encode("utf8"))
raise
resp["stdout"] = debug_stdout.getvalue()
resp["stderr"] = debug_stderr.getvalue()
try:
resp.update(self._response_metadata())
server.write(json.dumps(resp).encode("utf8"))
Expand Down