Skip to content

pet server logs warnings as ANSI-colored stderr, shown as errors #571

Open

Description

Problem: Since #314, pet server writes its diagnostics as ANSI-colored text on stderr instead of sending log notifications. The VS Code Python Environments extension logs every stderr chunk at error level, so routine warnings show up as [error] lines full of escape codes in the Python Environments output channel.

For example, on a Windows machine with only per-user Python installs, every startup logs:

[error] [pet] ␛[2m   0.008930700s␛[0m ␛[33m WARN␛[0m ␛[2mpet_windows_registry::environments␛[0m␛[2m:␛[0m Failed to open HKLM\Software\Python, Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }

Output channel filtered to [pet]: a WARN line logged as [error], with ESC control characters

These are the first "errors" users and triagers see in logs. Of 33 microsoft/vscode-python-environments issues that quote [error] [pet] lines, 15 include warnings logged this way (as ^[[33m WARN^[[0m), mostly pet_conda::package: Unable to find conda package … and pet_windows_registry::environments: Failed to open HKLM\Software\Python. For example microsoft/vscode-python-environments#1370 (71 such lines), microsoft/vscode-python-environments#1099 and microsoft/vscode-python-environments#1491.

Cause:

Suggested fix:

  • In server mode, forward tracing events as log notifications with their level (a tracing layer that reuses pet_reporter::jsonrpc::Log), and keep stderr for panics.
  • Disable ANSI colors when stderr is not a terminal (.with_ansi(std::io::stderr().is_terminal())).
  • Optionally, in the extension: log stderr by the level token in each line, not as errors.

Environment: Windows 11, VS Code 1.140.0, PET main @ 4ca7c03 with Python Environments main @ 52f6ace.

Steps to verify fix:

  1. On Windows without a machine-wide Python (no HKLM\Software\Python key), open a Python file in VS Code with Python Environments.
  2. Open the Output panel, select Python Environments, and filter by [pet].
  3. Verify the Failed to open HKLM\Software\Python message is logged as [warning] (or not at all at the default level) and contains no ␛[ sequences.
  4. Point python.defaultInterpreterPath at a missing file and reload; verify PET's resolve failure is still logged as [error].
  5. Run pet find 2> err.txt and verify err.txt has no ANSI escape codes.

Found by Copilot

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions